Package com.syntifi.crypto.key
Class Secp256k1PrivateKey
- java.lang.Object
-
- com.syntifi.crypto.key.AbstractPrivateKey
-
- com.syntifi.crypto.key.Secp256k1PrivateKey
-
public class Secp256k1PrivateKey extends AbstractPrivateKey
secp256k1 implementation ofAbstractPrivateKey- Since:
- 0.1.0
-
-
Constructor Summary
Constructors Constructor Description Secp256k1PrivateKey()Secp256k1PrivateKey(byte[] privateKey)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanEqual(java.lang.Object other)AbstractPublicKeyderivePublicKey()Returns a Secp256k1PublicKey object in a compressed format adding the prefix 02/03 to identify the positive or negative Y followed by the X value in the elliptic curvestatic Secp256k1PrivateKeyderiveRandomKey()booleanequals(java.lang.Object o)org.web3j.crypto.ECKeyPairgetKeyPair()inthashCode()voidloadPrivateKey(byte[] privateKey)Loads a private key from a byte arrayvoidreadPrivateKey(java.io.Reader reader)Reads the private key from a streamvoidsetKeyPair(org.web3j.crypto.ECKeyPair keyPair)byte[]sign(byte[] message)When encoded in DER, this becomes the following sequence of bytes:voidwritePrivateKey(java.io.Writer writer)Writes the private key to a file-
Methods inherited from class com.syntifi.crypto.key.AbstractPrivateKey
getKey, readPrivateKey, setKey, toString, writePrivateKey
-
-
-
-
Method Detail
-
loadPrivateKey
public void loadPrivateKey(byte[] privateKey) throws java.io.IOExceptionDescription copied from class:AbstractPrivateKeyLoads a private key from a byte array- Specified by:
loadPrivateKeyin classAbstractPrivateKey- Parameters:
privateKey- the private key bytes- Throws:
java.io.IOException
-
readPrivateKey
public void readPrivateKey(java.io.Reader reader) throws java.io.IOExceptionDescription copied from class:AbstractPrivateKeyReads the private key from a stream- Specified by:
readPrivateKeyin classAbstractPrivateKey- Parameters:
reader- the source of the private key- Throws:
java.io.IOException- thrown if an error occurs reading the file
-
writePrivateKey
public void writePrivateKey(java.io.Writer writer) throws java.io.IOExceptionDescription copied from class:AbstractPrivateKeyWrites the private key to a file- Specified by:
writePrivateKeyin classAbstractPrivateKey- Parameters:
writer- the target writer- Throws:
java.io.IOException- thrown if an error occurs writing the file
-
sign
public byte[] sign(byte[] message)
When encoded in DER, this becomes the following sequence of bytes:0x30 b1 0x02 b2 (vr) 0x02 b3 (vs)
where:
b1 is a single byte value, equal to the length, in bytes, of the remaining list of bytes (from the first 0x02 to the end of the encoding); b2 is a single byte value, equal to the length, in bytes, of (vr); b3 is a single byte value, equal to the length, in bytes, of (vs); (vr) is the signed big-endian encoding of the value "r
", of minimal length; (vs) is the signed big-endian encoding of the value "s ", of minimal length.
- Specified by:
signin classAbstractPrivateKey- Parameters:
message- message to sign- Returns:
- signed message
-
derivePublicKey
public AbstractPublicKey derivePublicKey()
Returns a Secp256k1PublicKey object in a compressed format adding the prefix 02/03 to identify the positive or negative Y followed by the X value in the elliptic curve- Specified by:
derivePublicKeyin classAbstractPrivateKey- Returns:
- the derived
AbstractPublicKey
-
deriveRandomKey
public static Secp256k1PrivateKey deriveRandomKey()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classAbstractPrivateKey
-
canEqual
protected boolean canEqual(java.lang.Object other)
- Overrides:
canEqualin classAbstractPrivateKey
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractPrivateKey
-
getKeyPair
public org.web3j.crypto.ECKeyPair getKeyPair()
-
setKeyPair
public void setKeyPair(org.web3j.crypto.ECKeyPair keyPair)
-
-