Package anbxj

Class Crypto_EncryptionEngine

java.lang.Object
anbxj.Crypto_EncryptionEngine

public class Crypto_EncryptionEngine extends Object
Cryptographic engine
  • 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.
  • 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()
      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

      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.