Package convex.core.crypto
Class AKeyPair
java.lang.Object
convex.core.crypto.AKeyPair
- Direct Known Subclasses:
BCKeyPair
Abstract base class for key pairs in Convex.
Intended as a lightweight container for underlying crypto primitives.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AKeyPair
create
(byte[] keyMaterial) Creates a key pair using specific key material.static AKeyPair
Create a key pair with the given seed.static AKeyPair
Create a KeyPair from a JCA KeyPairstatic AKeyPair
create
(PrivateKey privateKey) Create a KeyPair from given private key.static AKeyPair
create
(PublicKey publicKey, PrivateKey privateKey) Creates an Ed25519 Key Pair with the specified keysstatic AKeyPair
createSeeded
(long seed) Create a deterministic key pair with the given seed.abstract boolean
Tests if this keypair is equal to another key pair.final boolean
static AccountKey
extractAccountKey
(PublicKey publicKey) Extracts an AccountKey from an Ed25519 public keyprotected static Blob
extractSeed
(PrivateKey priv) Gets the seed from a JCA Private Key.static AKeyPair
generate()
Generates a new, secure random key pair.abstract AccountKey
Gets the Account Public Key of this KeyPairGets the JCA representation of this Key PairGets the JCA PrivateKeyGets the JCA PublicKeyfinal byte[]
Gets a new byte array representation of the public keyabstract Blob
getSeed()
Gets the Ed25519 seed for this key pairstatic PrivateKey
privateFromBytes
(byte[] privKey) Gets a Ed25519 Private Key from a 32-byte array.static PrivateKey
privateKeyFromBlob
(Blob encodedKey) static PrivateKey
privateKeyFromBytes
(byte[] key) Creates a private key using the given raw bytes.static PublicKey
publicKeyFromBytes
(byte[] key) abstract ASignature
sign
(AArrayBlob hash) Signs a hash value with this key pair, producing a signature of the appropriate type.abstract <R extends ACell>
SignedData<R>signData
(R value) Signs a value with this key pairtoString()
-
Field Details
-
SEED_LENGTH
public static final int SEED_LENGTH- See Also:
-
ED25519
- See Also:
-
-
Constructor Details
-
AKeyPair
public AKeyPair()
-
-
Method Details
-
getPublicKeyBytes
public final byte[] getPublicKeyBytes()Gets a new byte array representation of the public key- Returns:
- Bytes of public key
-
getAccountKey
Gets the Account Public Key of this KeyPair- Returns:
- AccountKey for this KeyPair
-
signData
Signs a value with this key pair- Type Parameters:
R
- Type of Value- Parameters:
value
- Value to sign. Can be any valid CVM value.- Returns:
- Signed Data Object
-
equals
-
equals
Tests if this keypair is equal to another key pair. Generally, a key pair should be considered equal if it has the same public key and produces identical signatures in all cases.- Parameters:
kp
- Other key pair to compare with- Returns:
- True if key pairs are equal
-
sign
Signs a hash value with this key pair, producing a signature of the appropriate type.- Parameters:
hash
- Hash of value to sign- Returns:
- A Signature compatible with the key pair.
-
createSeeded
Create a deterministic key pair with the given seed. SECURITY: Never use this for valuable keys or real assets: intended for deterministic testing only.- Parameters:
seed
- Any long value. The same seed will produce the same key pair.- Returns:
- New key pair
-
generate
Generates a new, secure random key pair. Uses a Java SecureRandom instance.- Returns:
- New Key Pair instance.
-
create
Creates a key pair using specific key material.- Parameters:
keyMaterial
- Bytes to use as key- Returns:
- New key pair
-
create
Create a key pair with the given seed. Public key is generated automatically from the private key- Parameters:
seed
- 32 bytes of seed material- Returns:
- A new key pair using the given seed
-
getPrivate
Gets the JCA PrivateKey- Returns:
- Private Key
-
getPublic
Gets the JCA PublicKey- Returns:
- Public Key
-
toString
-
getJCAKeyPair
Gets the JCA representation of this Key Pair- Returns:
- JCA KepPair
-
extractSeed
Gets the seed from a JCA Private Key. Should always be last 32 bytes of the encoding- Parameters:
priv
- Private Key in JCA format- Returns:
-
getSeed
Gets the Ed25519 seed for this key pair- Returns:
- Seed blob of 32 bytes
-
create
Create a KeyPair from given private key. Public key is generated automatically from the private key- Parameters:
privateKey
- An PrivateKey item for private key- Returns:
- A new key pair using the given private key
-
create
Creates an Ed25519 Key Pair with the specified keys- Parameters:
publicKey
- Public keyprivateKey
- Private key- Returns:
- Key Pair instance
-
create
Create a KeyPair from a JCA KeyPair- Parameters:
keyPair
- JCA KeyPair- Returns:
- AKeyPair instance
-
privateKeyFromBytes
Creates a private key using the given raw bytes.- Parameters:
key
- 32 bytes private key data- Returns:
- Ed25519 Private Key instance
-
extractAccountKey
Extracts an AccountKey from an Ed25519 public key- Parameters:
publicKey
- Public key- Returns:
- AccountKey instance
-
privateKeyFromBlob
-
privateFromBytes
Gets a Ed25519 Private Key from a 32-byte array.- Parameters:
privKey
- Bytes to use as a private key seed- Returns:
- PrivateKey instance
-
publicKeyFromBytes
-