Interface CryptoProvider


  • public interface CryptoProvider
    Interface defining the contract for a cryptographic provider (e.g., SODIUM, HYDROGEN). It provides methods for key creation, key pairing, and cryptographic operations.
    • 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​(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.
      • deriveSymmetricKeys

        PairSymKeys deriveSymmetricKeys​(AKey.Symmetric masterKey,
                                        int serverId,
                                        int keyNumber)
        Derives a pair of symmetric keys (for client-to-server and server-to-client communication) using Key Derivation Function (KDF) from a master key and session/key identifiers.
        Parameters:
        masterKey - The master symmetric key.
        serverId - The server identifier (32-bit).
        keyNumber - The key number/index (32-bit).
        Returns:
        A PairSymmetricKeys object containing client and server keys.
      • createKeyForServer

        default PairSymKeys 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.
      • 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.
      • createKey

        default <T extends AKey> T createKey​(KeyType keyType,
                                             java.lang.String publicKey)
        Creates a key from its type and public key's hexadecimal string.
        Parameters:
        keyType - The type of key to create.
        publicKey - The hexadecimal string of the public key data.
        Returns:
        A new AKey instance.