public final class CoverCrypt extends Object
| Constructor and Description |
|---|
CoverCrypt()
Instantiate a
CoverCrypt instance by loading the native library `cosmian_cover_crypt`. |
CoverCrypt(CoverCryptWrapper instance) |
| Modifier and Type | Method and Description |
|---|---|
String |
booleanAccessPolicyToJson(String booleanExpression)
Convert a boolean access policy expression to JSON that can be used in KMIP calls to create user decryption keys.
|
int |
createDecryptionCache(byte[] userDecryptionKeyBytes)
Create a decryption cache that can be used with
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up the decryption of the header. |
int |
createDecryptionCache(PrivateKey userDecryptionKey)
Create an decryption cache that can be used with
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up decryption of the header WARN: the cache MUST be destroyed after use with
destroyDecryptionCache(int) |
int |
createEncryptionCache(Policy policy,
byte[] publicKeyBytes)
Create an encryption cache that can be used with
encryptHeaderUsingCache(int, String) Use of the cache
speeds up the encryption of the header. |
int |
createEncryptionCache(PublicKey publicKey)
Create an encryption cache that can be used with
encryptHeaderUsingCache(int, String) se of the cache
speeds up the encryption of the header. |
DecryptedData |
decrypt(byte[] userDecryptionKeyBytes,
byte[] ciphertext)
Decrypt a hybrid encryption
|
DecryptedData |
decrypt(byte[] userDecryptionKeyBytes,
byte[] ciphertext,
byte[] authenticationData)
Decrypt a hybrid encryption
|
byte[] |
decryptBlock(byte[] symmetricKey,
byte[] encryptedBytes)
Symmetrically decrypt a block of encrypted data.
|
byte[] |
decryptBlock(byte[] symmetricKey,
byte[] authenticationData,
byte[] encryptedBytes)
Symmetrically decrypt a block of encrypted data.
|
DecryptedHeader |
decryptHeader(byte[] userDecryptionKeyBytes,
byte[] encryptedHeaderBytes)
Decrypt a hybrid header, recovering the symmetric key, and optionally, the resource UID and additional data
|
DecryptedHeader |
decryptHeader(byte[] userDecryptionKeyBytes,
byte[] encryptedHeaderBytes,
int additionalDataLen,
Optional<byte[]> authenticationData)
Decrypt a hybrid header, recovering the symmetric key, and optionally, the resource UID and additional data
|
DecryptedHeader |
decryptHeader(PrivateKey userDecryptionKey,
byte[] encryptedHeaderBytes)
Decrypt a hybrid header, recovering the symmetric key
|
DecryptedHeader |
decryptHeader(PrivateKey userDecryptionKey,
byte[] encryptedHeaderBytes,
int additionalDataLen,
Optional<byte[]> authenticationData)
Decrypt a hybrid header, recovering the symmetric key, and optionally, the resource UID and additional data
|
DecryptedHeader |
decryptHeaderUsingCache(int cacheHandle,
byte[] encryptedHeaderBytes)
Decrypt a hybrid header using a cache, recovering the symmetric key
|
DecryptedHeader |
decryptHeaderUsingCache(int cacheHandle,
byte[] encryptedHeaderBytes,
int additionalDataLen,
Optional<byte[]> authenticationData)
Decrypt a hybrid header using a cache, recovering the symmetric key, and optionally, the resource UID and
additional data
|
void |
destroyDecryptionCache(int cacheHandle)
Destroy the cache created with
createDecryptionCache(byte[]) |
void |
destroyEncryptionCache(int cacheHandle)
Destroy the cache created with
createEncryptionCache(Policy, byte[]) |
byte[] |
encrypt(Policy policy,
byte[] publicKeyBytes,
String encryptionPolicy,
byte[] plaintext)
Generate an hybrid encryption of a plaintext.
|
byte[] |
encrypt(Policy policy,
byte[] publicKeyBytes,
String encryptionPolicy,
byte[] plaintext,
byte[] authenticationData)
Generate an hybrid encryption of a plaintext.
|
byte[] |
encrypt(Policy policy,
byte[] publicKeyBytes,
String encryptionPolicy,
byte[] plaintext,
byte[] authenticationData,
byte[] headerMetadata)
Generate an hybrid encryption of a plaintext.
|
byte[] |
encryptBlock(byte[] symmetricKey,
byte[] clearText)
Symmetrically encrypt a block of clear text data.
|
byte[] |
encryptBlock(byte[] symmetricKey,
byte[] authenticationData,
byte[] clearText)
Symmetrically encrypt a block of clear text data.
|
EncryptedHeader |
encryptHeader(Policy policy,
byte[] publicKeyBytes,
String encryptionPolicy)
Generate an hybrid encryption header.
|
EncryptedHeader |
encryptHeader(Policy policy,
byte[] publicKeyBytes,
String encryptionPolicy,
Optional<byte[]> additionalData,
Optional<byte[]> authenticationData)
Generate an hybrid encryption header.
|
EncryptedHeader |
encryptHeader(PublicKey publicKey,
String encryptionPolicy)
Generate an hybrid encryption header.
|
EncryptedHeader |
encryptHeader(PublicKey publicKey,
String encryptionPolicy,
Optional<byte[]> additionalData,
Optional<byte[]> authenticationData)
Generate an hybrid encryption header.
|
EncryptedHeader |
encryptHeaderUsingCache(int cacheHandle,
String encryptionPolicy)
Generate an hybrid encryption header using a pre-cached Public Key and Policy.
|
EncryptedHeader |
encryptHeaderUsingCache(int cacheHandle,
String encryptionPolicy,
Optional<byte[]> additionalData,
Optional<byte[]> authenticationData)
Generate an hybrid encryption header using a pre-cached Public Key and Policy.
|
MasterKeys |
generateMasterKeys(Policy policy)
Generate the master private and public keys using the ABE policy
|
byte[] |
generateUserPrivateKey(byte[] masterPrivateKey,
AccessPolicy accessPolicy,
Policy policy)
Generate the user private key
|
byte[] |
generateUserPrivateKey(byte[] masterPrivateKey,
String booleanAccessPolicy,
Policy policy)
Generate the user private key
|
String |
get_last_error()
Return the last error in a String that does not exceed 1023 bytes
|
String |
get_last_error(int max_len)
Return the last error in a String that does not exceed `max_len` bytes
|
Policy |
rotateAttributes(Attr[] attributes,
Policy policy)
Rotate attributes, changing their underlying value with that of an unused slot
|
void |
set_error(String error_msg)
Set the last error on the native lib
|
int |
symmetricEncryptionOverhead()
The overhead in bytes (over the clear text) generated by the symmetric encryption scheme (AES 256 GCM)
|
int |
unwrap(int result)
If the result of the last FFI call is in Error, recover the last error from the native code and throw an
exception wrapping it.
|
public CoverCrypt()
CoverCrypt instance by loading the native library `cosmian_cover_crypt`. The library must
be on the classpath. Native libraries are already included for darwin-x86-64, linux-x86-64 and win32-x86-64public CoverCrypt(CoverCryptWrapper instance)
public String get_last_error() throws CloudproofException
CloudproofException - in case of native library errorpublic String get_last_error(int max_len) throws CloudproofException
max_len - the maximum number of bytes to returnCloudproofException - in case of native library errorpublic void set_error(String error_msg) throws CloudproofException
error_msg - the last error to set on the native libCloudproofException - n case of native library errorpublic int createEncryptionCache(PublicKey publicKey) throws CloudproofException
encryptHeaderUsingCache(int, String) se of the cache
speeds up the encryption of the header. WARN: the cache MUST be destroyed after use with
destroyEncryptionCache(int)publicKey - the public key to cacheCloudproofException - on Rust lib errorsCloudproofException - in case of other errorspublic int createEncryptionCache(Policy policy, byte[] publicKeyBytes) throws CloudproofException
encryptHeaderUsingCache(int, String) Use of the cache
speeds up the encryption of the header. WARN: the cache MUST be destroyed after use with
destroyEncryptionCache(int)policy - the Policy to cachepublicKeyBytes - the public key bytes to cacheCloudproofException - on Rust lib errorsCloudproofException - in case of other errorspublic void destroyEncryptionCache(int cacheHandle)
throws CloudproofException
createEncryptionCache(Policy, byte[])cacheHandle - the pointer to the cache to destroyCloudproofException - on Rust lib errorsCloudproofException - in case of other errorspublic EncryptedHeader encryptHeaderUsingCache(int cacheHandle, String encryptionPolicy) throws CloudproofException
cacheHandle - the pointer to the intencryptionPolicy - the encryption policy that determines the partitions to encrypt forCloudproofException - in case of native library errorCloudproofException - in case the Policy and key bytes cannot be recovered from the
PublicKeypublic EncryptedHeader encryptHeaderUsingCache(int cacheHandle, String encryptionPolicy, Optional<byte[]> additionalData, Optional<byte[]> authenticationData) throws CloudproofException
cacheHandle - the pointer to the intencryptionPolicy - the encryption policy that determines the partitions to encrypt foradditionalData - optional additional data to encrypt and add to the headerauthenticationData - optional data used to authenticate the encryption of the additional dataCloudproofException - in case of native library errorCloudproofException - in case the Policy and key bytes cannot be recovered from the
PublicKeypublic EncryptedHeader encryptHeader(PublicKey publicKey, String encryptionPolicy) throws CloudproofException
publicKey - the ABE public key also holds the PolicyencryptionPolicy - the encryption policy that determines the partitions to encrypt forCloudproofException - in case of native library errorCloudproofException - in case the Policy and key bytes cannot be recovered from the
PublicKeypublic EncryptedHeader encryptHeader(PublicKey publicKey, String encryptionPolicy, Optional<byte[]> additionalData, Optional<byte[]> authenticationData) throws CloudproofException
publicKey - the ABE public key also holds the PolicyencryptionPolicy - the encryption policy that determines the partitions to encrypt foradditionalData - the additional data to encrypt and add to the headerauthenticationData - optional data used to authenticate the encryption of the additional dataCloudproofException - in case of native library errorCloudproofException - in case the Policy and key bytes cannot be recovered from the
PublicKeypublic EncryptedHeader encryptHeader(Policy policy, byte[] publicKeyBytes, String encryptionPolicy) throws CloudproofException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt forCloudproofException - in case of native library errorpublic EncryptedHeader encryptHeader(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, Optional<byte[]> additionalData, Optional<byte[]> authenticationData) throws CloudproofException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt foradditionalData - the additional data to encrypt and add to the headerauthenticationData - optional data used to authenticate the encryption of the additional dataCloudproofException - in case of native library errorpublic int createDecryptionCache(PrivateKey userDecryptionKey) throws CloudproofException
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up decryption of the header WARN: the cache MUST be destroyed after use with
destroyDecryptionCache(int)userDecryptionKey - the public key to cacheCloudproofException - on Rust lib errorsCloudproofException - in case of other errorspublic int createDecryptionCache(byte[] userDecryptionKeyBytes)
throws CloudproofException
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up the decryption of the header. WARN: the cache MUST be destroyed after use with
destroyDecryptionCache(int)userDecryptionKeyBytes - the public key bytes to cacheCloudproofException - on Rust lib errorsCloudproofException - in case of other errorspublic void destroyDecryptionCache(int cacheHandle)
throws CloudproofException
createDecryptionCache(byte[])cacheHandle - the pointer to the cache to destroyCloudproofException - on Rust lib errorsCloudproofException - in case of other errorspublic DecryptedHeader decryptHeaderUsingCache(int cacheHandle, byte[] encryptedHeaderBytes) throws CloudproofException
cacheHandle - the cache to the user decryption keyencryptedHeaderBytes - the encrypted headerCloudproofException - in case of native library errorCloudproofException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeaderUsingCache(int cacheHandle, byte[] encryptedHeaderBytes, int additionalDataLen, Optional<byte[]> authenticationData) throws CloudproofException
cacheHandle - the cache to the user decryption keyencryptedHeaderBytes - the encrypted headeradditionalDataLen - the maximum bytes length of the expected additional dataauthenticationData - optional data used to authenticate the encryption of the additional dataCloudproofException - in case of native library errorpublic DecryptedHeader decryptHeader(PrivateKey userDecryptionKey, byte[] encryptedHeaderBytes) throws CloudproofException
userDecryptionKey - the ABE user decryption keyencryptedHeaderBytes - the encrypted headerCloudproofException - in case of native library errorCloudproofException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeader(PrivateKey userDecryptionKey, byte[] encryptedHeaderBytes, int additionalDataLen, Optional<byte[]> authenticationData) throws CloudproofException
userDecryptionKey - the ABE user decryption keyencryptedHeaderBytes - the encrypted headeradditionalDataLen - the maximum bytes length of the expected additional dataauthenticationData - optional data used to authenticate the encryption of the additional dataCloudproofException - in case of native library errorCloudproofException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeader(byte[] userDecryptionKeyBytes, byte[] encryptedHeaderBytes) throws CloudproofException
userDecryptionKeyBytes - the ABE user decryption key bytesencryptedHeaderBytes - the encrypted headerCloudproofException - in case of native library errorpublic DecryptedHeader decryptHeader(byte[] userDecryptionKeyBytes, byte[] encryptedHeaderBytes, int additionalDataLen, Optional<byte[]> authenticationData) throws CloudproofException
userDecryptionKeyBytes - the ABE user decryption key bytesencryptedHeaderBytes - the encrypted headeradditionalDataLen - the maximum bytes length of the expected additional dataauthenticationData - optional data used to authenticate the encryption of the additional dataCloudproofException - in case of native library errorpublic int symmetricEncryptionOverhead()
public byte[] encryptBlock(byte[] symmetricKey,
byte[] clearText)
throws CloudproofException
symmetricKey - The key to use to symmetrically encrypt the blockclearText - the clear text to encryptCloudproofException - in case of native library errorpublic byte[] encryptBlock(byte[] symmetricKey,
byte[] authenticationData,
byte[] clearText)
throws CloudproofException
symmetricKey - The key to use to symmetrically encrypt the blockauthenticationData - The associated Data used to authenticate the symmetric encryptionclearText - the clear text to encryptCloudproofException - in case of native library errorpublic byte[] decryptBlock(byte[] symmetricKey,
byte[] encryptedBytes)
throws CloudproofException
symmetricKey - the symmetric key to useencryptedBytes - the encrypted block bytesCloudproofException - in case of native library errorpublic byte[] decryptBlock(byte[] symmetricKey,
byte[] authenticationData,
byte[] encryptedBytes)
throws CloudproofException
symmetricKey - the symmetric key to useauthenticationData - The associated Data used to authenticate the symmetric encryptionencryptedBytes - the encrypted block bytesCloudproofException - in case of native library errorpublic MasterKeys generateMasterKeys(Policy policy) throws CloudproofException
policy - the policy to useCloudproofException - in case of native library errorpublic byte[] generateUserPrivateKey(byte[] masterPrivateKey,
String booleanAccessPolicy,
Policy policy)
throws CloudproofException
masterPrivateKey - the master private key in bytesbooleanAccessPolicy - the access policy of the user private key as an boolean expressionpolicy - the ABE policyCloudproofException - in case of native library errorpublic byte[] generateUserPrivateKey(byte[] masterPrivateKey,
AccessPolicy accessPolicy,
Policy policy)
throws CloudproofException
masterPrivateKey - the master private key in bytesaccessPolicy - the access policy of the user private key as an AccessPolicy instancepolicy - the ABE policyCloudproofException - in case of native library errorpublic Policy rotateAttributes(Attr[] attributes, Policy policy) throws CloudproofException, com.fasterxml.jackson.core.exc.StreamReadException, com.fasterxml.jackson.databind.DatabindException, IOException
attributes: - a list of attributes to rotatepolicy: - the current policy returns the new PolicyCloudproofException - in case of native library errorIOException - standard IO exceptionscom.fasterxml.jackson.databind.DatabindException - standard databind exceptionscom.fasterxml.jackson.core.exc.StreamReadException - stream read exceptionspublic int unwrap(int result)
throws CloudproofException
result - the result of the FFI callCloudproofException - in case of native library error (result is 1)public byte[] encrypt(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, byte[] plaintext) throws CloudproofException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt forplaintext - the plaintext to encryptCloudproofException - in case of native library errorpublic byte[] encrypt(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, byte[] plaintext, byte[] authenticationData) throws CloudproofException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt forplaintext - the plaintext to encryptauthenticationData - data used to authenticate the symmetric encryptionCloudproofException - in case of native library errorpublic byte[] encrypt(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, byte[] plaintext, byte[] authenticationData, byte[] headerMetadata) throws CloudproofException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt forplaintext - the plaintext to encryptauthenticationData - data used to authenticate the symmetric encryptionheaderMetadata - additional data to encrypt and add to the headerCloudproofException - in case of native library errorpublic DecryptedData decrypt(byte[] userDecryptionKeyBytes, byte[] ciphertext) throws CloudproofException
userDecryptionKeyBytes - the ABE user decryption key bytesciphertext - the ciphertext to decryptDecryptedData containing the plaintext and optional header metadataCloudproofException - in case of native library errorpublic DecryptedData decrypt(byte[] userDecryptionKeyBytes, byte[] ciphertext, byte[] authenticationData) throws CloudproofException
userDecryptionKeyBytes - the ABE user decryption key bytesciphertext - the ciphertext to decryptauthenticationData - data used to authenticate the symmetric encryptionDecryptedData containing the plaintext and optional header metadataCloudproofException - in case of native library errorpublic String booleanAccessPolicyToJson(String booleanExpression) throws CloudproofException
booleanExpression - access policy in the form of a boolean expressionStringCloudproofException - in case of native library errorCopyright © 2022. All rights reserved.