Package org.wso2.carbon.crypto.api
Interface CryptoService
public interface CryptoService
The service contract of an implementation of a crypto service.
The service provides crypto related functionality such as signing and decrypting.
-
Method Summary
Modifier and TypeMethodDescriptiondefault byte[]customDecrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider, Object... params) Computes and returns the plain text of a given cipher text.default byte[]customEncrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, boolean returnSelfContainedCipherText, Object... params) Computes and returns the ciphertext of the given cleartext.byte[]Computes and returns the cleartext of the given ciphertext.default byte[]decrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider, String internalCryptoProviderType) Computes and returns the plain text of a given cipher text.byte[]decrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) Computes and returns the cleartext of the given ciphertext comes from an external entity.byte[]Computes and returns the ciphertext of the given cleartext.default byte[]encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, boolean returnSelfContainedCipherText) Computes and returns the ciphertext of the given cleartext.default byte[]encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, boolean returnSelfContainedCipherText, String internalCryptoProviderType) Computes and returns the cipher text of the given cleartext.byte[]encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) Computes and returns the ciphertext of the given cleartext, using asymmetric cryptography.getCertificate(CryptoContext cryptoContext) Returns theCertificatebased on the givenCryptoContext.default byte[]hybridDecrypt(HybridEncryptionOutput hybridEncryptionOutput, String symmetricAlgorithm, String asymmetricAlgorithm, String javaSecurityProvider, CryptoContext cryptoContext) In hybrid decryption symmetric key used for encryption is decrypted with asymmetric decryption and cipher data is decrypted using symmetric decryption mechanism.default HybridEncryptionOutputhybridEncrypt(HybridEncryptionInput hybridEncryptionInput, String symmetricAlgorithm, String asymmetricAlgorithm, String javaSecurityProvider, CryptoContext cryptoContext) In hybrid encryption clear data is encrypted using symmetric encryption mechanism and symmetric key used for encryption is encrypted with asymmetric encryption.byte[]sign(byte[] data, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) Computes and returns the signature of given data.booleanverifySignature(byte[] data, byte[] signature, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) Verifies whether given signature of the given data was generated by a trusted external party.
-
Method Details
-
encrypt
byte[] encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider) throws CryptoException Computes and returns the ciphertext of the given cleartext.The encrypted data is only for internal usage (e.g. encrypting passwords before persisting), therefore the ciphertext is NOT supposed to be shared with other systems.
- Parameters:
cleartext- The cleartext to be encrypted.algorithm- The encryption / decryption algorithmjavaSecurityAPIProvider- The Java Security API provider.- Returns:
- The ciphertext
- Throws:
CryptoException- If something unexpected happens during the encryption operation.
-
decrypt
byte[] decrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider) throws CryptoException Computes and returns the cleartext of the given ciphertext.The input ciphertext should be a ciphertext which was generated from
encrypt(byte[], String, String)method.- Parameters:
ciphertext- The ciphertext to be decrypted.algorithm- The signature + hashing algorithm to be used in signing.javaSecurityAPIProvider- The Java Security API provider.- Returns:
- The cleartext
- Throws:
CryptoException- If something unexpected happens during the decryption operation.
-
sign
byte[] sign(byte[] data, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) throws CryptoException Computes and returns the signature of given data.- Parameters:
data- The content which the signature should be generated against.algorithm- The signature + hashing algorithm to be used in signing.javaSecurityAPIProvider- The Java Security API provider.cryptoContext- The context information which is needed to discover the private key.- Returns:
- The digital signature of given data.
- Throws:
CryptoException- If something unexpected happens during the signing operation.
-
decrypt
byte[] decrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) throws CryptoException Computes and returns the cleartext of the given ciphertext comes from an external entity. Asymmetric cryptography is used for decryption.- Parameters:
ciphertext- The content which the signature should be generated against.algorithm- The signature + hashing algorithm to be used in signing.javaSecurityAPIProvider- The Java Security API provider.cryptoContext- The context information which is needed to discover the private key.- Returns:
- An array of bytes which contains the signature.
- Throws:
CryptoException- If something unexpected happens during the decryption operation.
-
encrypt
byte[] encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) throws CryptoException Computes and returns the ciphertext of the given cleartext, using asymmetric cryptography. This ciphertext is indented to be used and decrypted by an external entity.- Parameters:
cleartext- The cleartext to be encrypted.algorithm- The signature + hashing algorithm to be used in signing.javaSecurityAPIProvider- The Java Security API provider.cryptoContext- The context information which is needed to discover the public key of the external entity.- Returns:
- The encrypted data.
- Throws:
CryptoException- If something unexpected happens during the encryption operation.
-
verifySignature
boolean verifySignature(byte[] data, byte[] signature, String algorithm, String javaSecurityAPIProvider, CryptoContext cryptoContext) throws CryptoException Verifies whether given signature of the given data was generated by a trusted external party.- Parameters:
data- The data which was the signature generated on.signature- The signature bytes of data.algorithm- The signature + hashing algorithm to be used in signing.javaSecurityAPIProvider- The Java Security API provider.cryptoContext- The context information which is needed to discover the public key of the external entity.- Returns:
- true if signature can be verified, false otherwise.
- Throws:
CryptoException- If something unexpected happens during the signature verification.
-
getCertificate
Returns theCertificatebased on the givenCryptoContext.- Parameters:
cryptoContext- The context information which is used to discover the public key of the external entity.- Returns:
- The
Certificaterelates with the given context. - Throws:
CryptoException- If something unexpected happens during certificate discovery.
-
hybridEncrypt
default HybridEncryptionOutput hybridEncrypt(HybridEncryptionInput hybridEncryptionInput, String symmetricAlgorithm, String asymmetricAlgorithm, String javaSecurityProvider, CryptoContext cryptoContext) throws CryptoException In hybrid encryption clear data is encrypted using symmetric encryption mechanism and symmetric key used for encryption is encrypted with asymmetric encryption. Computes and return aHybridEncryptionOutputbased on provided clear data.- Parameters:
hybridEncryptionInput- Input data for hybrid encryption.symmetricAlgorithm- The symmetric encryption/decryption algorithm.asymmetricAlgorithm- The asymmetric encryption/decryption algorithm.javaSecurityProvider- The Java Security API provider.cryptoContext- The context information which is used to discover the public key of the external entity.- Returns:
HybridEncryptionOutputcipher text with required parameters- Throws:
CryptoException
-
hybridDecrypt
default byte[] hybridDecrypt(HybridEncryptionOutput hybridEncryptionOutput, String symmetricAlgorithm, String asymmetricAlgorithm, String javaSecurityProvider, CryptoContext cryptoContext) throws CryptoException In hybrid decryption symmetric key used for encryption is decrypted with asymmetric decryption and cipher data is decrypted using symmetric decryption mechanism. Computes and return clear data based on providedHybridEncryptionOutput- Parameters:
hybridEncryptionOutput-HybridEncryptionOutputciphered data with parameters.symmetricAlgorithm- The symmetric encryption/decryption algorithm.asymmetricAlgorithm- The asymmetric encryption/decryption algorithm.javaSecurityProvider- The Java Security API provider.cryptoContext- The context information which is used to discover the public key of the external entity.- Returns:
- the decrypted data
- Throws:
CryptoException
-
encrypt
default byte[] encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, boolean returnSelfContainedCipherText) throws CryptoException Computes and returns the ciphertext of the given cleartext. If using assymetric encryption and returnSelfContainedCipherText is true, the cipher text will be a self contained cipher text. The encrypted data is only for internal usage (e.g. encrypting passwords before persisting), therefore the ciphertext is NOT supposed to be shared with other systems.- Parameters:
cleartext- The cleartext to be encrypted.algorithm- The encryption / decryption algorithmjavaSecurityAPIProvider- The Java Security API provider.returnSelfContainedCipherText- Whether cipher text need to be self contained.- Returns:
- The ciphertext
- Throws:
CryptoException- If something unexpected happens during the encryption operation.
-
encrypt
default byte[] encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, boolean returnSelfContainedCipherText, String internalCryptoProviderType) throws CryptoException Computes and returns the cipher text of the given cleartext. In this method api, we can pass the internalCryptoProviderType and get the clear text encrypted using the preferred internal crypto provider.- Parameters:
cleartext- The cleartext to be encrypted.algorithm- The encryption algorithm.javaSecurityAPIProvider- The Java Security API provider.returnSelfContainedCipherText- Whether cipher text need to be self contained.internalCryptoProviderType- Preferred internal crypto provider.- Returns:
- The ciphertext
- Throws:
CryptoException- If something unexpected happens during the encryption operation.
-
decrypt
default byte[] decrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider, String internalCryptoProviderType) throws CryptoException Computes and returns the plain text of a given cipher text. In this method api, we can pass the internalCryptoProviderType and get the cipher text decrypted using the preferred internal crypto provider.- Parameters:
ciphertext- The encrypted text.algorithm- The encryption algorithm.javaSecurityAPIProvider- The Java Security API provider.internalCryptoProviderType- Preferred internal crypto provider.- Returns:
- TThe clear text in byte array format.
- Throws:
CryptoException
-
customDecrypt
default byte[] customDecrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider, Object... params) throws CryptoException Computes and returns the plain text of a given cipher text. If using assymetric encryption and the cipher text is a self contained cipher text, the cipher text will be decrypted using the private key of the current entity.- Parameters:
ciphertext- The encrypted text.algorithm- The encryption algorithm.javaSecurityAPIProvider- The Java Security API provider.params- Additional parameters required for decryption.- Returns:
- The clear text in byte array format.
- Throws:
CryptoException
-
customEncrypt
default byte[] customEncrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider, boolean returnSelfContainedCipherText, Object... params) throws CryptoException Computes and returns the ciphertext of the given cleartext. If using assymetric encryption and returnSelfContainedCipherText is true, the cipher text will be a self contained cipher text. The encrypted data is only for internal usage (e.g. encrypting passwords before persisting), therefore the ciphertext is NOT supposed to be shared with other systems.- Parameters:
cleartext- The cleartext to be encrypted.algorithm- The encryption / decryption algorithmjavaSecurityAPIProvider- The Java Security API provider.returnSelfContainedCipherText- Whether cipher text need to be self contained.params- Custom parameters required for encryption.- Returns:
- The ciphertext
- Throws:
CryptoException- If something unexpected happens during the encryption operation.
-