Package io.aether.crypto
Interface CryptoProvider
-
public interface CryptoProviderInterface defining the contract for a cryptographic provider (e.g., SODIUM, HYDROGEN). It provides methods for key creation, key pairing, and cryptographic operations.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CryptoEnginecreateAsymmetricEngine(AKey.AsymmetricPrivate privateKey, AKey.AsymmetricPublic publicKey)Creates a CryptoEngine for asymmetric decryption.CryptoEnginecreateAsymmetricEngine(AKey.AsymmetricPublic key)Creates a CryptoEngine for asymmetric encryption.CryptoEnginecreateAsymmetricEngine(PairAsymKeys keys)Creates a CryptoEngine for asymmetric decryption from a key pair.PairAsymKeyscreateAsymmetricKeys()Generates a new pair of asymmetric keys (public and private).<T extends AKey>
TcreateKey(KeyType keyType, byte[] data)Creates a concrete AKey implementation based on the specified key type and data.default <T extends AKey>
TcreateKey(KeyType keyType, java.lang.String publicKey)Creates a key from its type and public key's hexadecimal string.<T extends AKey>
TcreateKey(java.lang.String data)Creates a key from its textual representation, which is generated by AKey.toString.default AKey.SymmetriccreateKeyForClient(AKey.Symmetric masterKey, int sid)Creates a symmetric key for client-side usage from a master key and session ID.default AKey.SymmetriccreateKeyForServer(AKey.Symmetric masterKey, int sid)Creates a symmetric key for server-side usage from a master key and session ID.SigncreateSign(byte[] data)Creates a Sign object from raw byte data.SigncreateSign(java.lang.String data)Creates a Sign object from its textual representation, which is generated by Sign.toString.default SignedKeycreateSignedKey(KeyType keyType, byte[] key, byte[] sign)Creates a SignedKey from key type, raw key bytes, and raw signature bytes.default SignedKeycreateSignedKey(java.lang.String data)Parses a signed key string into a SignedKey object.default SignercreateSigner()Creates a Signer object using newly generated signing keys.SignercreateSigner(AKey.SignPublic publicKey)Creates a Signer object solely for signature verification.SignercreateSigner(AKey.SignPublic publicKey, AKey.SignPrivate privateKey)Creates a Signer object for signature verification and creation from explicit keys.SignercreateSigner(PairSignKeys keys)PairSignKeyscreateSignKeys()Generates a new pair of signing keys (public and private).default PairSignKeyscreateSignKeys(byte[] publicKey, byte[] privateKey)Creates a pair of signing keys from raw byte arrays.default PairSignKeyscreateSignKeys(java.lang.String text)Creates a pair of signing keys from a textual representation.default PairSignKeyscreateSignKeys(java.lang.String publicKey, java.lang.String privateKey)Creates a pair of signing keys from hexadecimal strings.AKey.SignPrivatecreateSignPrivateKey(byte[] data)Creates a private signing key from raw byte data.AKey.SignPubliccreateSignPublicKey(byte[] data)Creates a public signing key from raw byte data.CryptoEnginecreateSymmetricEngine(AKey.Symmetric key)Creates a CryptoEngine for symmetric encryption and decryption.AKey.SymmetriccreateSymmetricKey()Generates a new random symmetric key.AKey.SymmetriccreateSymmetricKey(byte[] bytes)Creates a symmetric key from raw byte data.java.lang.StringgetCryptoLibName()Gets the unique name of the cryptographic library implemented by this provider.
-
-
-
Method Detail
-
getCryptoLibName
java.lang.String getCryptoLibName()
Gets the unique name of the cryptographic library implemented by this provider.- Returns:
- The name of the crypto library (e.g., "SODIUM", "HYDROGEN").
-
createAsymmetricKeys
PairAsymKeys createAsymmetricKeys()
Generates a new pair of asymmetric keys (public and private).- Returns:
- A PairAsymKeys object containing the generated keys.
-
createSymmetricKey
AKey.Symmetric createSymmetricKey()
Generates a new random symmetric key.- Returns:
- A new AKey.Symmetric instance.
-
createSignKeys
PairSignKeys createSignKeys()
Generates a new pair of signing keys (public and private).- Returns:
- A PairSignKeys object containing the generated keys.
-
createSignedKey
default SignedKey createSignedKey(java.lang.String data)
Parses a signed key string into a SignedKey object. The method is flexible, supporting both ':' and '|' as the separator between KEY_DATA and SIGN_DATA. The key provider and sign provider are assumed to be the current provider. Expected formats (4 parts): 1. PROVIDER:KEY_TYPE:KEY_DATA:SIGN_DATA 2. PROVIDER:KEY_TYPE:KEY_DATA|SIGN_DATA- Parameters:
data- The signed key string.- Returns:
- A new SignedKey instance.
- Throws:
java.lang.IllegalArgumentException- if the format is invalid or provider mismatch.
-
createSignKeys
default PairSignKeys createSignKeys(byte[] publicKey, byte[] privateKey)
Creates a pair of signing keys from raw byte arrays.- Parameters:
publicKey- The byte array of the public key.privateKey- The byte array of the private key.- Returns:
- A new PairSignKeys instance.
-
createSignKeys
default PairSignKeys createSignKeys(java.lang.String publicKey, java.lang.String privateKey)
Creates a pair of signing keys from hexadecimal strings.- Parameters:
publicKey- The hexadecimal string of the public key.privateKey- The hexadecimal string of the private key.- Returns:
- A new PairSignKeys instance.
-
createSigner
Signer createSigner(PairSignKeys keys)
-
createSigner
Signer createSigner(AKey.SignPublic publicKey, AKey.SignPrivate privateKey)
Creates a Signer object for signature verification and creation from explicit keys.- Parameters:
publicKey- The public signing key.privateKey- The private signing key.- Returns:
- A new Signer instance.
-
createSigner
Signer createSigner(AKey.SignPublic publicKey)
Creates a Signer object solely for signature verification.- Parameters:
publicKey- The public signing key.- Returns:
- A new Signer instance configured only for verification.
-
createSymmetricEngine
CryptoEngine createSymmetricEngine(AKey.Symmetric key)
Creates a CryptoEngine for symmetric encryption and decryption. This engine will handle its own internal state, such as a nonce.- Parameters:
key- The AKey.SymmetricKey to be used.- Returns:
- A new CryptoEngine instance.
-
createAsymmetricEngine
CryptoEngine createAsymmetricEngine(AKey.AsymmetricPublic key)
Creates a CryptoEngine for asymmetric encryption.- Parameters:
key- The AKey.AsymmetricPublicKey to be used.- Returns:
- A new CryptoEngine instance.
-
createAsymmetricEngine
CryptoEngine createAsymmetricEngine(AKey.AsymmetricPrivate privateKey, AKey.AsymmetricPublic publicKey)
Creates a CryptoEngine for asymmetric decryption.- Parameters:
privateKey- The AKey.AsymmetricPrivateKey to be used.publicKey- The AKey.AsymmetricPublicKey of the sender.- Returns:
- A new CryptoEngine instance.
-
createAsymmetricEngine
CryptoEngine createAsymmetricEngine(PairAsymKeys keys)
Creates a CryptoEngine for asymmetric decryption from a key pair.- Parameters:
keys- The pair of asymmetric keys.- Returns:
- A new CryptoEngine instance.
-
createKey
<T extends AKey> T createKey(KeyType keyType, byte[] data)
Creates a concrete AKey implementation based on the specified key type and data.- Parameters:
keyType- The type of key to create.data- The byte array of the key.- Returns:
- A new AKey instance.
-
createKey
<T extends AKey> T createKey(java.lang.String data)
Creates a key from its textual representation, which is generated by AKey.toString. The expected format is "PROVIDER:KEY_TYPE:KEY_DATA".- Parameters:
data- The textual key representation.- Returns:
- A new AKey instance.
-
createSignedKey
default SignedKey createSignedKey(KeyType keyType, byte[] key, byte[] sign)
Creates a SignedKey from key type, raw key bytes, and raw signature bytes.- Parameters:
keyType- The type of key.key- The raw key bytes.sign- The raw signature bytes.- Returns:
- A new SignedKey instance.
-
createSign
Sign createSign(java.lang.String data)
Creates a Sign object from its textual representation, which is generated by Sign.toString. The expected format is "PROVIDER:SIGN_DATA".- Parameters:
data- The textual sign representation.- Returns:
- A new Sign instance.
-
createSign
Sign createSign(byte[] data)
Creates a Sign object from raw byte data.- Parameters:
data- The raw signature bytes.- Returns:
- A new Sign instance.
-
createKeyForServer
default AKey.Symmetric createKeyForServer(AKey.Symmetric masterKey, int sid)
Creates a symmetric key for server-side usage from a master key and session ID. Default implementation returns the master key itself.- Parameters:
masterKey- The master symmetric key.sid- The session ID.- Returns:
- The symmetric key for the server.
-
createKeyForClient
default AKey.Symmetric createKeyForClient(AKey.Symmetric masterKey, int sid)
Creates a symmetric key for client-side usage from a master key and session ID. Default implementation returns the master key itself.- Parameters:
masterKey- The master symmetric key.sid- The session ID.- Returns:
- The symmetric key for the client.
-
createSignPublicKey
AKey.SignPublic createSignPublicKey(byte[] data)
Creates a public signing key from raw byte data.- Parameters:
data- The raw public key bytes.- Returns:
- A new AKey.SignPublic instance.
-
createSignPrivateKey
AKey.SignPrivate createSignPrivateKey(byte[] data)
Creates a private signing key from raw byte data.- Parameters:
data- The raw private key bytes.- Returns:
- A new AKey.SignPrivate instance.
-
createSignKeys
default PairSignKeys createSignKeys(java.lang.String text)
Creates a pair of signing keys from a textual representation. The method handles two formats: 1. FULL_PUB_KEY_STRING|FULL_PRIV_KEY_STRING (for rootSigners.key parsing). 2. PROVIDER:PUBLIC_KEY_HEX[:PRIVATE_KEY_HEX] (2 or 3 sections). 3. PUBLIC_KEY_HEX[:PRIVATE_KEY_HEX] (Legacy format, 1 or 2 sections).- Parameters:
text- The textual key pair representation.- Returns:
- A new PairSignKeys instance.
-
createSymmetricKey
AKey.Symmetric createSymmetricKey(byte[] bytes)
Creates a symmetric key from raw byte data.- Parameters:
bytes- The raw symmetric key bytes.- Returns:
- A new AKey.Symmetric instance.
-
createSigner
default Signer createSigner()
Creates a Signer object using newly generated signing keys.- Returns:
- A new Signer instance.
-
-