public class ECKey
extends java.lang.Object
implements java.io.Serializable
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ECKey.ECDSASignature |
static class |
ECKey.MissingPrivateKeyException |
| 限定符和类型 | 字段和说明 |
|---|---|
static org.spongycastle.crypto.params.ECDomainParameters |
CURVE
The parameters of the secp256k1 curve.
|
static org.spongycastle.jce.spec.ECParameterSpec |
CURVE_SPEC |
static java.math.BigInteger |
HALF_CURVE_ORDER
Equal to CURVE.getN().shiftRight(1), used for canonicalising the S value of a
signature.
|
protected org.spongycastle.math.ec.ECPoint |
pub |
| 构造器和说明 |
|---|
ECKey()
Generates an entirely new keypair.
|
ECKey(java.math.BigInteger priv,
org.spongycastle.math.ec.ECPoint pub)
Pair a private key integer with a public EC point
BouncyCastle will be used as the Java Security Provider
|
ECKey(java.security.Provider provider,
java.security.PrivateKey privKey,
org.spongycastle.math.ec.ECPoint pub)
Pair a private key with a public EC point.
|
ECKey(java.security.Provider provider,
java.security.SecureRandom secureRandom)
Generate a new keypair using the given Java Security Provider.
|
ECKey(java.security.SecureRandom secureRandom)
Generates an entirely new keypair with the given
SecureRandom object. |
| 限定符和类型 | 方法和说明 |
|---|---|
ECKey |
compress()
已过时。
per-point compression property will be removed in Bouncy Castle
|
static org.spongycastle.math.ec.ECPoint |
compressPoint(org.spongycastle.math.ec.ECPoint uncompressed)
已过时。
per-point compression property will be removed in Bouncy Castle
|
static byte[] |
computeAddress(byte[] pubBytes)
Compute an address from an encoded public key.
|
static byte[] |
computeAddress(org.spongycastle.math.ec.ECPoint pubPoint)
Compute an address from a public point.
|
ECKey |
decompress()
已过时。
per-point compression property will be removed in Bouncy Castle
|
static org.spongycastle.math.ec.ECPoint |
decompressPoint(org.spongycastle.math.ec.ECPoint compressed)
已过时。
per-point compression property will be removed in Bouncy Castle
|
byte[] |
decryptAES(byte[] cipher)
已过时。
should not use EC private scalar value as an AES key
|
ECKey.ECDSASignature |
doSign(byte[] input)
Signs the given hash and returns the R and S components as BigIntegers and
put them in ECDSASignature
|
boolean |
equals(java.lang.Object o) |
static org.spongycastle.math.ec.ECPoint |
extractPublicKey(java.security.interfaces.ECPublicKey ecPublicKey) |
static ECKey |
fromNodeId(byte[] nodeId)
Recover the public key from an encoded node id.
|
static ECKey |
fromPrivate(java.math.BigInteger privKey)
Creates an ECKey given the private key only.
|
static ECKey |
fromPrivate(byte[] privKeyBytes)
Creates an ECKey given the private key only.
|
static ECKey |
fromPrivateAndPrecalculatedPublic(java.math.BigInteger priv,
org.spongycastle.math.ec.ECPoint pub)
Creates an ECKey that simply trusts the caller to ensure that point is really
the result of multiplying the generator point by the private key.
|
static ECKey |
fromPrivateAndPrecalculatedPublic(byte[] priv,
byte[] pub)
Creates an ECKey that simply trusts the caller to ensure that point is really
the result of multiplying the generator point by the private key.
|
static ECKey |
fromPublicOnly(byte[] pub)
Creates an ECKey that cannot be used for signing, only verifying signatures,
from the given encoded point.
|
static ECKey |
fromPublicOnly(org.spongycastle.math.ec.ECPoint pub)
Creates an ECKey that cannot be used for signing, only verifying signatures,
from the given point.
|
byte[] |
getAddress()
Gets the address form of the public key.
|
byte[] |
getNodeId()
Generates the NodeID based on this key, that is the public key without first
format byte
|
java.math.BigInteger |
getPrivKey()
Gets the private key in the form of an integer field element.
|
byte[] |
getPrivKeyBytes()
Returns a 32 byte array containing the private key, or null if the key is
encrypted or public only
|
byte[] |
getPubKey()
Gets the encoded public key value.
|
org.spongycastle.math.ec.ECPoint |
getPubKeyPoint()
Gets the public key in the form of an elliptic curve point object from Bouncy
Castle.
|
int |
hashCode() |
boolean |
hasPrivKey()
Returns true if this key has access to private key bytes.
|
boolean |
isCompressed()
Returns whether this key is using the compressed form or not.
|
boolean |
isPubKeyCanonical()
Returns true if this pubkey is canonical, i.e. the correct length taking into
account compression.
|
static boolean |
isPubKeyCanonical(byte[] pubkey)
Returns true if the given pubkey is canonical, i.e. the correct length taking
into account compression.
|
boolean |
isPubKeyOnly()
Returns true if this key doesn't have access to private key bytes.
|
java.math.BigInteger |
keyAgreement(org.spongycastle.math.ec.ECPoint otherParty) |
static byte[] |
pubBytesWithoutFormat(org.spongycastle.math.ec.ECPoint pubPoint)
Compute the encoded X, Y coordinates of a public point.
|
static byte[] |
publicKeyFromPrivate(java.math.BigInteger privKey,
boolean compressed)
Returns public key bytes from the given private key.
|
static byte[] |
recoverAddressFromSignature(int recId,
ECKey.ECDSASignature sig,
byte[] messageHash) |
static ECKey |
recoverFromSignature(int recId,
ECKey.ECDSASignature sig,
byte[] messageHash) |
static byte[] |
recoverPubBytesFromSignature(int recId,
ECKey.ECDSASignature sig,
byte[] messageHash)
Given the components of a signature and a selector value, recover and return
the public key that generated the signature according to the algorithm in
SEC1v2 section 4.1.6.
|
ECKey.ECDSASignature |
sign(byte[] messageHash)
Takes the keccak hash (32 bytes) of data and returns the ECDSA signature
|
static byte[] |
signatureToAddress(byte[] messageHash,
ECKey.ECDSASignature sig)
Compute the address of the key that signed the given signature.
|
static byte[] |
signatureToAddress(byte[] messageHash,
java.lang.String signatureBase64)
Compute the address of the key that signed the given signature.
|
static ECKey |
signatureToKey(byte[] messageHash,
ECKey.ECDSASignature sig)
Compute the key that signed the given signature.
|
static ECKey |
signatureToKey(byte[] messageHash,
java.lang.String signatureBase64)
Compute the key that signed the given signature.
|
static byte[] |
signatureToKeyBytes(byte[] messageHash,
ECKey.ECDSASignature sig) |
static byte[] |
signatureToKeyBytes(byte[] messageHash,
java.lang.String signatureBase64)
Given a piece of text and a message signature encoded in base64, returns an
ECKey containing the public key that was used to sign it.
|
java.lang.String |
toString() |
java.lang.String |
toStringWithPrivate()
Produce a string rendering of the ECKey INCLUDING the private key.
|
boolean |
verify(byte[] data,
byte[] signature)
Verifies the given ASN.1 encoded ECDSA signature against a hash using the
public key.
|
static boolean |
verify(byte[] data,
byte[] signature,
byte[] pub)
Verifies the given ASN.1 encoded ECDSA signature against a hash using the
public key.
|
boolean |
verify(byte[] sigHash,
ECKey.ECDSASignature signature)
Verifies the given R/S pair (signature) against a hash using the public key.
|
static boolean |
verify(byte[] data,
ECKey.ECDSASignature signature,
byte[] pub)
Verifies the given ECDSA signature against the message bytes using the public
key bytes.
|
public static final org.spongycastle.crypto.params.ECDomainParameters CURVE
public static final org.spongycastle.jce.spec.ECParameterSpec CURVE_SPEC
public static final java.math.BigInteger HALF_CURVE_ORDER
protected final org.spongycastle.math.ec.ECPoint pub
public ECKey()
public ECKey(java.security.Provider provider,
java.security.SecureRandom secureRandom)
provider - providersecureRandom - secureRandompublic ECKey(java.security.SecureRandom secureRandom)
SecureRandom object.
BouncyCastle will be used as the Java Security ProvidersecureRandom - -public ECKey(java.security.Provider provider,
java.security.PrivateKey privKey,
org.spongycastle.math.ec.ECPoint pub)
provider - providerprivKey - privKeypub - pubpublic ECKey(java.math.BigInteger priv,
org.spongycastle.math.ec.ECPoint pub)
priv - privkeypub - pubkeypublic static org.spongycastle.math.ec.ECPoint extractPublicKey(java.security.interfaces.ECPublicKey ecPublicKey)
public static org.spongycastle.math.ec.ECPoint compressPoint(org.spongycastle.math.ec.ECPoint uncompressed)
uncompressed - -public static org.spongycastle.math.ec.ECPoint decompressPoint(org.spongycastle.math.ec.ECPoint compressed)
compressed - -public static ECKey fromPrivate(java.math.BigInteger privKey)
privKey - -public static ECKey fromPrivate(byte[] privKeyBytes)
privKeyBytes - -public static ECKey fromPrivateAndPrecalculatedPublic(java.math.BigInteger priv, org.spongycastle.math.ec.ECPoint pub)
priv - -pub - -public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub)
priv - -pub - -public static ECKey fromPublicOnly(org.spongycastle.math.ec.ECPoint pub)
pub - -public static ECKey fromPublicOnly(byte[] pub)
pub - -public ECKey decompress()
public ECKey compress()
public boolean isPubKeyOnly()
public boolean hasPrivKey()
isPubKeyOnly().public static byte[] publicKeyFromPrivate(java.math.BigInteger privKey,
boolean compressed)
privKey - -compressed - -public static byte[] computeAddress(byte[] pubBytes)
pubBytes - an encoded (uncompressed) public keypublic static byte[] computeAddress(org.spongycastle.math.ec.ECPoint pubPoint)
pubPoint - a public pointpublic byte[] getAddress()
public static byte[] pubBytesWithoutFormat(org.spongycastle.math.ec.ECPoint pubPoint)
pubPoint - a public pointpublic byte[] getNodeId()
public static ECKey fromNodeId(byte[] nodeId)
nodeId - a 64-byte X,Y point pairpublic byte[] getPubKey()
public org.spongycastle.math.ec.ECPoint getPubKeyPoint()
public java.math.BigInteger getPrivKey()
java.lang.IllegalStateException - if the private key bytes are not available.public boolean isCompressed()
public java.lang.String toString()
toString 在类中 java.lang.Objectpublic java.lang.String toStringWithPrivate()
public ECKey.ECDSASignature doSign(byte[] input)
input - to signpublic ECKey.ECDSASignature sign(byte[] messageHash)
messageHash - -java.lang.IllegalStateException - if this ECKey does not have the private part.public static byte[] signatureToKeyBytes(byte[] messageHash,
java.lang.String signatureBase64)
throws java.security.SignatureException
messageHash - a piece of human readable text that was signedsignatureBase64 - The message signature in base64java.security.SignatureException - If the public key could not be recovered or if there was a
signature format error.public static byte[] signatureToKeyBytes(byte[] messageHash,
ECKey.ECDSASignature sig)
throws java.security.SignatureException
java.security.SignatureExceptionpublic static byte[] signatureToAddress(byte[] messageHash,
java.lang.String signatureBase64)
throws java.security.SignatureException
messageHash - 32-byte hash of messagesignatureBase64 - Base-64 encoded signaturejava.security.SignatureException - SignatureExceptionpublic static byte[] signatureToAddress(byte[] messageHash,
ECKey.ECDSASignature sig)
throws java.security.SignatureException
messageHash - 32-byte hash of messagesig - -java.security.SignatureException - SignatureExceptionpublic static ECKey signatureToKey(byte[] messageHash, java.lang.String signatureBase64) throws java.security.SignatureException
messageHash - 32-byte hash of messagesignatureBase64 - Base-64 encoded signaturejava.security.SignatureException - SignatureExceptionpublic static ECKey signatureToKey(byte[] messageHash, ECKey.ECDSASignature sig) throws java.security.SignatureException
messageHash - 32-byte hash of messagesig - sigjava.security.SignatureException - SignatureExceptionpublic java.math.BigInteger keyAgreement(org.spongycastle.math.ec.ECPoint otherParty)
public byte[] decryptAES(byte[] cipher)
cipher - -proper cipherpublic static boolean verify(byte[] data,
ECKey.ECDSASignature signature,
byte[] pub)
Verifies the given ECDSA signature against the message bytes using the public key bytes.
When using native ECDSA verification, data must be 32 bytes, and no element may be larger than 520 bytes.
data - Hash of the data to verify.signature - signature.pub - The public key bytes to use.public static boolean verify(byte[] data,
byte[] signature,
byte[] pub)
data - Hash of the data to verify.signature - signature.pub - The public key bytes to use.public boolean verify(byte[] data,
byte[] signature)
data - Hash of the data to verify.signature - signature.public boolean verify(byte[] sigHash,
ECKey.ECDSASignature signature)
sigHash - -signature - -public boolean isPubKeyCanonical()
public static boolean isPubKeyCanonical(byte[] pubkey)
pubkey - -public static byte[] recoverPubBytesFromSignature(int recId,
ECKey.ECDSASignature sig,
byte[] messageHash)
Given the components of a signature and a selector value, recover and return the public key that generated the signature according to the algorithm in SEC1v2 section 4.1.6.
The recId is an index from 0 to 3 which indicates which of the 4 possible keys is the correct one. Because the key recovery operation yields multiple potential keys, the correct key must either be stored alongside the signature, or you must be willing to try each recId in turn until you find one that outputs the key you are expecting.
If this method returns null it means recovery was not possible and recId should be iterated.
Given the above two points, a correct usage of this method is inside a for loop from 0 to 3, and if the output is null OR a key that is not the one you expect, you try again with the next recId.
recId - Which possible key to recover.sig - the R and S components of the signature, wrapped.messageHash - Hash of the data that was signed.public static byte[] recoverAddressFromSignature(int recId,
ECKey.ECDSASignature sig,
byte[] messageHash)
recId - Which possible key to recover.sig - the R and S components of the signature, wrapped.messageHash - Hash of the data that was signed.public static ECKey recoverFromSignature(int recId, ECKey.ECDSASignature sig, byte[] messageHash)
recId - Which possible key to recover.sig - the R and S components of the signature, wrapped.messageHash - Hash of the data that was signed.public byte[] getPrivKeyBytes()
public boolean equals(java.lang.Object o)
equals 在类中 java.lang.Objectpublic int hashCode()
hashCode 在类中 java.lang.ObjectCopyright © 2018. All Rights Reserved.