Package anbxj
Class Crypto_EncryptionEngine
java.lang.Object
anbxj.Crypto_EncryptionEngine
Cryptographic engine
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for Crypto_EncryptionEngine.Crypto_EncryptionEngine
(Crypto_KeyStoreBuilder_Map ksbd, Crypto_Config config) Constructor for Crypto_EncryptionEngine. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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.decrypt
(Crypto_SealedPair sc, Crypto_KeyPair pair) Decrypts a sealed pair using the provided key pair.Decrypts a sealed pair using the provided key store type.decrypt
(SealedObject so, SecretKey symmetricKey) Decrypts a sealed object using the provided symmetric key.decryptAsymPK
(SealedObject so, PrivateKey privateKey) Decrypts a sealed object using the provided private key.encrypt
(Object object, String alias, Crypto_KeyStoreType pk) Encrypts an object with the specified alias and key store type.Encrypts an object with the provided public key.Encrypts an object with the provided symmetric key and returns the sealed object.encryptCompare
(Object object, String alias, Crypto_KeyStoreType pk) Encrypts an object with a symmetric key, and also computes a digest for comparison.Generates a secret key for HMAC.static void
getInfo()
Displays information about available providers and algorithms.Generates a key pair for key exchange based on the configured key agreement algorithm.getKeyEx_PublicKey
(KeyPair keyPair) Retrieves the public key from a key pair generated for key exchange.getKeyEx_SecretKey
(PublicKey publicKey, KeyPair keyPair) Retrieves the secret key for key exchange based on the public and private keys.Generates a key pair.Gets the public key from a key pair.Retrieves the key store settings map.Retrieves the local certificate for a specified key store type.Retrieves a map of local certificates for different key store types.Retrieves the alias associated with a key store type.getNonce()
Generates and retrieves a nonce (number used once).getPublicKey
(String alias, Crypto_KeyStoreType pk) Retrieves the public key associated with the specified alias and key store type.getRemoteCertificate
(String alias, Crypto_KeyStoreType pk) Retrieves the remote certificate associated with a specified alias and key store type.getRemoteCertificates
(String alias) Retrieves a map of remote certificates associated with a specified alias.Generates a symmetric key.getSymmetricKeyPBE
(String password, String salt) Generates a symmetric key using a password and salt.Retrieves the current timestamp as an Instant.Gets the TSA CertPath.makeDigest
(Object obj) Calculates the digest of an object.Creates an HMAC pair using a specified alias.makeHmacRnd
(Object obj, SecretKey sk) Creates an HMAC pair using a secret key as a randomiser.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
Sets the TSA CertPath by retrieving it from the KeyStoreBuilder.void
setTSA_CertPath
(CertPath tSA_CertPath) Sets the TSA CertPath.sign
(Object object, Crypto_KeyPair kp) Signs an object using the private key from the provided key pair.sign
(Object object, Crypto_KeyStoreType sk) Signs an object using the private key associated with the specified key store type.verify
(SignedObject so, String alias, Crypto_KeyStoreType sk) Verifies a SignedObject using the public key associated with the specified alias and key store type.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.xor
(Crypto_ByteArray x1, Crypto_ByteArray x2) Performs bitwise XOR on two Crypto_ByteArrays and returns the result.
-
Constructor Details
-
Crypto_EncryptionEngine
Constructor for Crypto_EncryptionEngine.- Parameters:
ksbd
- The Crypto_KeyStoreBuilder_Map.
-
Crypto_EncryptionEngine
Constructor for Crypto_EncryptionEngine.- Parameters:
ksbd
- The Crypto_KeyStoreBuilder_Map.config
- The Crypto_Config.
-
-
Method Details
-
writeObject
Writes an object to a file.- Parameters:
obj
- The object to write.filename
- The filename to save the object.
-
readObject
Reads an object from a file.- Parameters:
filename
- The filename to read the object from.- Returns:
- The read object.
-
getKeyPair
Generates a key pair.- Returns:
- The generated key pair.
-
getKeyPair_PublicKey
Gets the public key from a key pair.- Parameters:
pair
- The key pair.- Returns:
- The public key.
-
checkDigest
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
Calculates the digest of an object.- Parameters:
obj
- The object to calculate the digest.- Returns:
- The calculated digest.
-
makeHmacValue
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
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
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
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
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
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
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
Generates a symmetric key.- Returns:
- The generated symmetric key.
-
getHmacKey
Generates a secret key for HMAC.- Returns:
- The generated HMAC key.
-
decrypt
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
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
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
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
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
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
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
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
Retrieves the key store settings map.- Returns:
- The key store settings map.
-
getLocaleCertificate
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
Retrieves a map of local certificates for different key store types.- Returns:
- A map containing local certificates for various key store types.
-
getMyAlias
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
Generates and retrieves a nonce (number used once).- Returns:
- A
Crypto_ByteArray
containing the generated nonce.
-
getTimeStamp
Retrieves the current timestamp as an Instant.- Returns:
- The current timestamp.
-
getRemoteCertificate
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
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
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
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
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
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
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
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
Generates a key pair for key exchange based on the configured key agreement algorithm.- Returns:
- KeyPair object containing public and private keys.
-
getKeyEx_PublicKey
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
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
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
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.
-