Package anbxj

# Class Crypto_EncryptionEngine

java.lang.Object
anbxj.Crypto_EncryptionEngine

public class Crypto_EncryptionEngine extends Object
Cryptographic engine

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Crypto_EncryptionEngine(Crypto_Config config)`
  Constructor for Crypto_EncryptionEngine.
  `Crypto_EncryptionEngine(Crypto_KeyStoreBuilder_Map ksbd)`
  Constructor for Crypto_EncryptionEngine.
  `Crypto_EncryptionEngine(Crypto_KeyStoreBuilder_Map ksbd, Crypto_Config config)`
  Constructor for Crypto_EncryptionEngine.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `checkDigest(Object obj, Crypto_ByteArray digest)`
  Checks if a given digest matches the calculated digest of an object.
  `boolean`
  `checkHmacPair(Object obj, Crypto_HmacPair hmac)`
  Verifies the integrity of an HMAC pair.
  `boolean`
  `checkHmacPairRnd(Object obj, Crypto_HmacPair hmac, SecretKey sk)`
  Verifies the integrity of an HMAC pair using a secret key as a randomizer.
  `boolean`
  `checkHmacValue(Object obj, Crypto_ByteArray hmac, SecretKey sk)`
  Verifies the integrity of an HMAC value.
  `boolean`
  `containsAlias(String alias)`
  Checks if the key store builder contains a specific alias.
  `Object`
  `decrypt(Crypto_SealedPair sc, Crypto_KeyPair pair)`
  Decrypts a sealed pair using the provided key pair.
  `Object`
  `decrypt(Crypto_SealedPair sc, Crypto_KeyStoreType pk)`
  Decrypts a sealed pair using the provided key store type.
  `Object`
  `decrypt(SealedObject so, SecretKey symmetricKey)`
  Decrypts a sealed object using the provided symmetric key.
  `Object`
  `decryptAsymPK(SealedObject so, PrivateKey privateKey)`
  Decrypts a sealed object using the provided private key.
  `Crypto_SealedPair`
  `encrypt(Object object, String alias, Crypto_KeyStoreType pk)`
  Encrypts an object with the specified alias and key store type.
  `Crypto_SealedPair`
  `encrypt(Object object, PublicKey publicKey)`
  Encrypts an object with the provided public key.
  `SealedObject`
  `encrypt(Object object, SecretKey symmetricKey)`
  Encrypts an object with the provided symmetric key and returns the sealed object.
  `Crypto_SealedPair`
  `encryptCompare(Object object, String alias, Crypto_KeyStoreType pk)`
  Encrypts an object with a symmetric key, and also computes a digest for comparison.
  `SecretKey`
  `getHmacKey()`
  Generates a secret key for HMAC.
  `static void`
  `getInfo()`
  Displays information about available providers and algorithms.
  `KeyPair`
  `getKeyEx_KeyPair()`
  Generates a key pair for key exchange based on the configured key agreement algorithm.
  `PublicKey`
  `getKeyEx_PublicKey(KeyPair keyPair)`
  Retrieves the public key from a key pair generated for key exchange.
  `SecretKey`
  `getKeyEx_SecretKey(PublicKey publicKey, KeyPair keyPair)`
  Retrieves the secret key for key exchange based on the public and private keys.
  `Crypto_KeyPair`
  `getKeyPair()`
  Generates a key pair.
  `PublicKey`
  `getKeyPair_PublicKey(Crypto_KeyPair pair)`
  Gets the public key from a key pair.
  `Crypto_KeyStoreSettings_Map`
  `getKeyStoreSettings_Map()`
  Retrieves the key store settings map.
  `Certificate`
  `getLocaleCertificate(Crypto_KeyStoreType kst)`
  Retrieves the local certificate for a specified key store type.
  `Map<Crypto_KeyStoreType,Certificate>`
  `getLocaleCertificates()`
  Retrieves a map of local certificates for different key store types.
  `String`
  `getMyAlias(Crypto_KeyStoreType kst)`
  Retrieves the alias associated with a key store type.
  `Crypto_ByteArray`
  `getNonce()`
  Generates and retrieves a nonce (number used once).
  `PublicKey`
  `getPublicKey(String alias, Crypto_KeyStoreType pk)`
  Retrieves the public key associated with the specified alias and key store type.
  `Certificate`
  `getRemoteCertificate(String alias, Crypto_KeyStoreType pk)`
  Retrieves the remote certificate associated with a specified alias and key store type.
  `Map<Crypto_KeyStoreType,Certificate>`
  `getRemoteCertificates(String alias)`
  Retrieves a map of remote certificates associated with a specified alias.
  `SecretKey`
  `getSymmetricKey()`
  Generates a symmetric key.
  `SecretKey`
  `getSymmetricKey(Crypto_KeyMode km)`
  Generates a symmetric key
  `SecretKey`
  `getSymmetricKeyPBE(String password, String salt)`
  Generates a symmetric key using a password and salt.
  `Instant`
  `getTimeStamp()`
  Retrieves the current timestamp as an Instant.
  `CertPath`
  `getTSA_CertPath()`
  Gets the TSA CertPath.
  `Crypto_ByteArray`
  `makeDigest(Object obj)`
  Calculates the digest of an object.
  `Crypto_HmacPair`
  `makeHmac(Object obj, String alias)`
  Creates an HMAC pair using a specified alias.
  `Crypto_HmacPair`
  `makeHmacRnd(Object obj, SecretKey sk)`
  Creates an HMAC pair using a secret key as a randomiser.
  `Crypto_ByteArray`
  `makeHmacValue(Object obj, SecretKey key)`
  Calculates the HMAC value of an object using a secret key.
  `static Object`
  `readObject(String filename)`
  Reads an object from a file.
  `void`
  `setTSA_CertPath()`
  Sets the TSA CertPath by retrieving it from the KeyStoreBuilder.
  `void`
  `setTSA_CertPath(CertPath tSA_CertPath)`
  Sets the TSA CertPath.
  `SignedObject`
  `sign(Object object, Crypto_KeyPair kp)`
  Signs an object using the private key from the provided key pair.
  `SignedObject`
  `sign(Object object, Crypto_KeyStoreType sk)`
  Signs an object using the private key associated with the specified key store type.
  `Object`
  `verify(SignedObject so, String alias, Crypto_KeyStoreType sk)`
  Verifies a SignedObject using the public key associated with the specified alias and key store type.
  `Object`
  `verify(SignedObject so, PublicKey publicKey)`
  Verifies a SignedObject using the provided public key.
  `static void`
  `writeObject(Object obj, String filename)`
  Writes an object to a file.
  `Crypto_ByteArray`
  `xor(Crypto_ByteArray x1, Crypto_ByteArray x2)`
  Performs bitwise XOR on two Crypto_ByteArrays and returns the result.

  ### Methods inherited from class java.lang.Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Crypto_EncryptionEngine

    public Crypto_EncryptionEngine(Crypto_KeyStoreBuilder_Map ksbd)
    Constructor for Crypto_EncryptionEngine.
    Parameters:
      `ksbd` - The Crypto_KeyStoreBuilder_Map.

  - ### Crypto_EncryptionEngine

    public Crypto_EncryptionEngine(Crypto_KeyStoreBuilder_Map ksbd, Crypto_Config config)
    Constructor for Crypto_EncryptionEngine.
    Parameters:
      `ksbd` - The Crypto_KeyStoreBuilder_Map.
      `config` - The Crypto_Config.

  - ### Crypto_EncryptionEngine

    public Crypto_EncryptionEngine(Crypto_Config config)
    Constructor for Crypto_EncryptionEngine.
    Parameters:
      `config` - The Crypto_Config.

- ## Method Details

  - ### writeObject

    public static void writeObject(Object obj, String filename)
    Writes an object to a file.
    Parameters:
      `obj` - The object to write.
      `filename` - The filename to save the object.

  - ### readObject

    public static Object readObject(String filename)
    Reads an object from a file.
    Parameters:
      `filename` - The filename to read the object from.
    Returns:
      The read object.

  - ### getKeyPair

    public Crypto_KeyPair getKeyPair()
    Generates a key pair.
    Returns:
      The generated key pair.

  - ### getKeyPair_PublicKey

    public PublicKey getKeyPair_PublicKey(Crypto_KeyPair pair)
    Gets the public key from a key pair.
    Parameters:
      `pair` - The key pair.
    Returns:
      The public key.

  - ### checkDigest

    public boolean checkDigest(Object obj, Crypto_ByteArray digest)
    Checks if a given digest matches the calculated digest of an object.
    Parameters:
      `obj` - The object to check the digest.
      `digest` - The digest to compare.
    Returns:
      True if the digests match, false otherwise.

  - ### makeDigest

    public Crypto_ByteArray makeDigest(Object obj)
    Calculates the digest of an object.
    Parameters:
      `obj` - The object to calculate the digest.
    Returns:
      The calculated digest.

  - ### makeHmacValue

    public Crypto_ByteArray makeHmacValue(Object obj, SecretKey key)
    Calculates the HMAC value of an object using a secret key.
    Parameters:
      `obj` - The object to calculate the HMAC value.
      `key` - The secret key for HMAC.
    Returns:
      The calculated HMAC value.

  - ### makeHmacRnd

    public Crypto_HmacPair makeHmacRnd(Object obj, SecretKey sk)
    Creates an HMAC pair using a secret key as a randomiser.
    Parameters:
      `obj` - The object to generate the HMAC pair.
      `sk` - The secret key for HMAC.
    Returns:
      The generated HMAC pair.

  - ### makeHmac

    public Crypto_HmacPair makeHmac(Object obj, String alias)
    Creates an HMAC pair using a specified alias.
    Parameters:
      `obj` - The object to generate the HMAC pair.
      `alias` - The alias for key generation.
    Returns:
      The generated HMAC pair.

  - ### checkHmacPair

    public boolean checkHmacPair(Object obj, Crypto_HmacPair hmac)
    Verifies the integrity of an HMAC pair.
    Parameters:
      `obj` - The object used to compute the original HMAC pair.
      `hmac` - The HMAC pair to verify.
    Returns:
      True if verification is successful, false otherwise.

  - ### checkHmacPairRnd

    public boolean checkHmacPairRnd(Object obj, Crypto_HmacPair hmac, SecretKey sk)
    Verifies the integrity of an HMAC pair using a secret key as a randomizer.
    Parameters:
      `obj` - The object used to compute the original HMAC pair.
      `hmac` - The HMAC pair to verify.
      `sk` - The secret key used for randomization.
    Returns:
      True if verification is successful, false otherwise.

  - ### checkHmacValue

    public boolean checkHmacValue(Object obj, Crypto_ByteArray hmac, SecretKey sk)
    Verifies the integrity of an HMAC value.
    Parameters:
      `obj` - The object used to compute the original HMAC.
      `hmac` - The HMAC value to verify.
      `sk` - The secret key for HMAC.
    Returns:
      True if verification is successful, false otherwise.

  - ### getSymmetricKeyPBE

    public SecretKey getSymmetricKeyPBE(String password, String salt)
    Generates a symmetric key using a password and salt.
    Parameters:
      `password` - The password for key generation.
      `salt` - The salt for key generation.
    Returns:
      The generated symmetric key.

  - ### getSymmetricKey

    public SecretKey getSymmetricKey(Crypto_KeyMode km)
    Generates a symmetric key
    Parameters:
      `km` - The key mode for the key generation
    Returns:
      The generated symmetric key.

  - ### getSymmetricKey

    public SecretKey getSymmetricKey()
    Generates a symmetric key.
    Returns:
      The generated symmetric key.

  - ### getHmacKey

    public SecretKey getHmacKey()
    Generates a secret key for HMAC.
    Returns:
      The generated HMAC key.

  - ### decrypt

    public Object decrypt(Crypto_SealedPair sc, Crypto_KeyStoreType pk)
    Decrypts a sealed pair using the provided key store type.
    Parameters:
      `sc` - The sealed pair to decrypt.
      `pk` - The key store type to obtain the private key for decryption.
    Returns:
      The decrypted object.

  - ### decrypt

    public Object decrypt(Crypto_SealedPair sc, Crypto_KeyPair pair)
    Decrypts a sealed pair using the provided key pair.
    Parameters:
      `sc` - The sealed pair to decrypt.
      `pair` - The key pair to obtain the private key for decryption.
    Returns:
      The decrypted object.

  - ### decryptAsymPK

    public Object decryptAsymPK(SealedObject so, PrivateKey privateKey)
    Decrypts a sealed object using the provided private key.
    Parameters:
      `so` - The sealed object to decrypt.
      `privateKey` - The private key to use for decryption.
    Returns:
      The decrypted object.

  - ### decrypt

    public Object decrypt(SealedObject so, SecretKey symmetricKey)
    Decrypts a sealed object using the provided symmetric key.
    Parameters:
      `so` - The sealed object to decrypt.
      `symmetricKey` - The symmetric key to use for decryption.
    Returns:
      The decrypted object.

  - ### encrypt

    public Crypto_SealedPair encrypt(Object object, String alias, Crypto_KeyStoreType pk)
    Encrypts an object with the specified alias and key store type.
    Parameters:
      `object` - The object to encrypt.
      `alias` - The alias to identify the public key.
      `pk` - The key store type to obtain the public key for encryption.
    Returns:
      The sealed pair containing the encrypted object and key.

  - ### encrypt

    public Crypto_SealedPair encrypt(Object object, PublicKey publicKey)
    Encrypts an object with the provided public key.
    Parameters:
      `object` - The object to encrypt.
      `publicKey` - The public key to use for encryption.
    Returns:
      The sealed pair containing the encrypted object and key.

  - ### encryptCompare

    public Crypto_SealedPair encryptCompare(Object object, String alias, Crypto_KeyStoreType pk)
    Encrypts an object with a symmetric key, and also computes a digest for comparison.
    Parameters:
      `object` - The object to encrypt.
      `alias` - The alias to identify the public key.
      `pk` - The key store type to obtain the public key for encryption.
    Returns:
      The sealed pair containing the encrypted object, key, and digest.

  - ### encrypt

    public SealedObject encrypt(Object object, SecretKey symmetricKey)
    Encrypts an object with the provided symmetric key and returns the sealed object.
    Parameters:
      `object` - The object to encrypt.
      `symmetricKey` - The symmetric key to use for encryption.
    Returns:
      The sealed object.

  - ### getKeyStoreSettings_Map

    public Crypto_KeyStoreSettings_Map getKeyStoreSettings_Map()
    Retrieves the key store settings map.
    Returns:
      The key store settings map.

  - ### getLocaleCertificate

    public Certificate getLocaleCertificate(Crypto_KeyStoreType kst)
    Retrieves the local certificate for a specified key store type.
    Parameters:
      `kst` - The key store type.
    Returns:
      The local certificate for the specified key store type.

  - ### getLocaleCertificates

    public Map<Crypto_KeyStoreType,Certificate> getLocaleCertificates()
    Retrieves a map of local certificates for different key store types.
    Returns:
      A map containing local certificates for various key store types.

  - ### getMyAlias

    public String getMyAlias(Crypto_KeyStoreType kst)
    Retrieves the alias associated with a key store type.
    Parameters:
      `kst` - The key store type.
    Returns:
      The alias associated with the specified key store type.

  - ### getNonce

    public Crypto_ByteArray getNonce()
    Generates and retrieves a nonce (number used once).
    Returns:
      A `Crypto_ByteArray` containing the generated nonce.

  - ### getTimeStamp

    public Instant getTimeStamp()
    Retrieves the current timestamp as an Instant.
    Returns:
      The current timestamp.

  - ### getRemoteCertificate

    public Certificate getRemoteCertificate(String alias, Crypto_KeyStoreType pk)
    Retrieves the remote certificate associated with a specified alias and key store type.
    Parameters:
      `alias` - The alias for the remote certificate.
      `pk` - The key store type.
    Returns:
      The remote certificate for the specified alias and key store type.

  - ### getRemoteCertificates

    public Map<Crypto_KeyStoreType,Certificate> getRemoteCertificates(String alias)
    Retrieves a map of remote certificates associated with a specified alias.
    Parameters:
      `alias` - The alias for which remote certificates are retrieved.
    Returns:
      A map containing remote certificates for various key store types.

  - ### containsAlias

    public boolean containsAlias(String alias)
    Checks if the key store builder contains a specific alias.
    Parameters:
      `alias` - The alias to check for existence.
    Returns:
      `true` if the alias exists; otherwise, `false`.

  - ### sign

    public SignedObject sign(Object object, Crypto_KeyStoreType sk)
    Signs an object using the private key associated with the specified key store type.
    Parameters:
      `object` - The object to sign.
      `sk` - The key store type.
    Returns:
      The SignedObject containing the signed object.

  - ### sign

    public SignedObject sign(Object object, Crypto_KeyPair kp)
    Signs an object using the private key from the provided key pair.
    Parameters:
      `object` - The object to sign.
      `kp` - The key pair containing the private key.
    Returns:
      The SignedObject containing the signed object.

  - ### getPublicKey

    public PublicKey getPublicKey(String alias, Crypto_KeyStoreType pk)
    Retrieves the public key associated with the specified alias and key store type.
    Parameters:
      `alias` - The alias for the remote public key.
      `pk` - The key store type.
    Returns:
      The remote public key for the specified alias and key store type.

  - ### verify

    public Object verify(SignedObject so, String alias, Crypto_KeyStoreType sk)
    Verifies a SignedObject using the public key associated with the specified alias and key store type.
    Parameters:
      `so` - The SignedObject to verify.
      `alias` - The alias for the remote public key.
      `sk` - The key store type.
    Returns:
      The verified object or null if verification fails.

  - ### verify

    public Object verify(SignedObject so, PublicKey publicKey)
    Verifies a SignedObject using the provided public key.
    Parameters:
      `so` - The SignedObject to verify.
      `publicKey` - The public key used for verification.
    Returns:
      The verified object or null if verification fails.

  - ### getKeyEx_KeyPair

    public KeyPair getKeyEx_KeyPair()
    Generates a key pair for key exchange based on the configured key agreement algorithm.
    Returns:
      KeyPair object containing public and private keys.

  - ### getKeyEx_PublicKey

    public PublicKey getKeyEx_PublicKey(KeyPair keyPair)
    Retrieves the public key from a key pair generated for key exchange.
    Parameters:
      `keyPair` - The KeyPair containing public and private keys.
    Returns:
      PublicKey object representing the public key.

  - ### getKeyEx_SecretKey

    public SecretKey getKeyEx_SecretKey(PublicKey publicKey, KeyPair keyPair)
    Retrieves the secret key for key exchange based on the public and private keys.
    Parameters:
      `publicKey` - The PublicKey of the other party.
      `keyPair` - The KeyPair containing the private key.
    Returns:
      SecretKey object representing the shared secret key.

  - ### getTSA_CertPath

    public CertPath getTSA_CertPath()
    Gets the TSA CertPath.
    Returns:
      The CertPath representing the TSA CertPath.

  - ### setTSA_CertPath

    public void setTSA_CertPath()
    Sets the TSA CertPath by retrieving it from the KeyStoreBuilder.

  - ### setTSA_CertPath

    public void setTSA_CertPath(CertPath tSA_CertPath)
    Sets the TSA CertPath.
    Parameters:
      `tSA_CertPath` - The CertPath to set as the TSA CertPath.

  - ### getInfo

    public static void getInfo()
    Displays information about available providers and algorithms.

  - ### xor

    public Crypto_ByteArray xor(Crypto_ByteArray x1, Crypto_ByteArray x2)
    Performs bitwise XOR on two Crypto_ByteArrays and returns the result.
    Parameters:
      `x1` - The first Crypto_ByteArray.
      `x2` - The second Crypto_ByteArray.
    Returns:
      A new Crypto_ByteArray representing the result of the XOR operation.