public final class Ffi extends Object
| Constructor and Description |
|---|
Ffi(FfiWrapper instance) |
| Modifier and Type | Method and Description |
|---|---|
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. |
byte[][] |
decrypt(byte[] userDecryptionKeyBytes,
byte[] ciphertext)
Decrypt a hybrid encryption
|
byte[][] |
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[] additionalData,
byte[] authenticationData)
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
|
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)
|
void |
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 Ffi(FfiWrapper instance)
public String get_last_error() throws FfiException
FfiException - in case of native library errorpublic String get_last_error(int max_len) throws FfiException
max_len - the maximum number of bytes to returnFfiException - in case of native library errorpublic void set_error(String error_msg) throws FfiException
error_msg - the last error to set on the native libFfiException - n case of native library errorpublic int createEncryptionCache(PublicKey publicKey) throws FfiException, CosmianException
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 cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic int createEncryptionCache(Policy policy, byte[] publicKeyBytes) throws FfiException, CosmianException
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 cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic void destroyEncryptionCache(int cacheHandle)
throws FfiException,
CosmianException
createEncryptionCache(Policy, byte[])cacheHandle - the pointer to the cache to destroyFfiException - on Rust lib errorsCosmianException - in case of other errorspublic EncryptedHeader encryptHeaderUsingCache(int cacheHandle, String encryptionPolicy) throws FfiException, CosmianException
cacheHandle - the pointer to the intencryptionPolicy - the encryption policy that determines the partitions to encrypt forFfiException - in case of native library errorCosmianException - 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 FfiException, CosmianException
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 dataFfiException - in case of native library errorCosmianException - in case the Policy and key bytes cannot be recovered from the PublicKeypublic EncryptedHeader encryptHeader(PublicKey publicKey, String encryptionPolicy) throws FfiException, CosmianException
publicKey - the ABE public key also holds the PolicyencryptionPolicy - the encryption policy that determines the partitions to encrypt forFfiException - in case of native library errorCosmianException - 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 FfiException, CosmianException
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 dataFfiException - in case of native library errorCosmianException - in case the Policy and key bytes cannot be recovered from the PublicKeypublic EncryptedHeader encryptHeader(Policy policy, byte[] publicKeyBytes, String encryptionPolicy) throws FfiException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt forFfiException - in case of native library errorpublic EncryptedHeader encryptHeader(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, Optional<byte[]> additionalData, Optional<byte[]> authenticationData) throws FfiException
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 dataFfiException - in case of native library errorpublic int createDecryptionCache(PrivateKey userDecryptionKey) throws FfiException, CosmianException
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 cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic int createDecryptionCache(byte[] userDecryptionKeyBytes)
throws FfiException,
CosmianException
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 cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic void destroyDecryptionCache(int cacheHandle)
throws FfiException,
CosmianException
createDecryptionCache(byte[])cacheHandle - the pointer to the cache to destroyFfiException - on Rust lib errorsCosmianException - in case of other errorspublic DecryptedHeader decryptHeaderUsingCache(int cacheHandle, byte[] encryptedHeaderBytes) throws FfiException, CosmianException
cacheHandle - the cache to the user decryption keyencryptedHeaderBytes - the encrypted headerFfiException - in case of native library errorCosmianException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeaderUsingCache(int cacheHandle, byte[] encryptedHeaderBytes, int additionalDataLen, Optional<byte[]> authenticationData) throws FfiException
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 dataFfiException - in case of native library errorpublic DecryptedHeader decryptHeader(PrivateKey userDecryptionKey, byte[] encryptedHeaderBytes) throws FfiException, CosmianException
userDecryptionKey - the ABE user decryption keyencryptedHeaderBytes - the encrypted headerFfiException - in case of native library errorCosmianException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeader(PrivateKey userDecryptionKey, byte[] encryptedHeaderBytes, int additionalDataLen, Optional<byte[]> authenticationData) throws FfiException, CosmianException
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 dataFfiException - in case of native library errorCosmianException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeader(byte[] userDecryptionKeyBytes, byte[] encryptedHeaderBytes) throws FfiException
userDecryptionKeyBytes - the ABE user decryption key bytesencryptedHeaderBytes - the encrypted headerFfiException - in case of native library errorpublic DecryptedHeader decryptHeader(byte[] userDecryptionKeyBytes, byte[] encryptedHeaderBytes, int additionalDataLen, Optional<byte[]> authenticationData) throws FfiException
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 dataFfiException - in case of native library errorpublic int symmetricEncryptionOverhead()
public byte[] encryptBlock(byte[] symmetricKey,
byte[] clearText)
throws FfiException
symmetricKey - The key to use to symmetrically encrypt the blockclearText - the clear text to encryptFfiException - in case of native library errorpublic byte[] encryptBlock(byte[] symmetricKey,
byte[] authenticationData,
byte[] clearText)
throws FfiException
symmetricKey - The key to use to symmetrically encrypt the blockauthenticationData - The associated Data used to authenticate the symmetric encryptionclearText - the clear text to encryptFfiException - in case of native library errorpublic byte[] decryptBlock(byte[] symmetricKey,
byte[] encryptedBytes)
throws FfiException
symmetricKey - the symmetric key to useencryptedBytes - the encrypted block bytesFfiException - in case of native library errorpublic byte[] decryptBlock(byte[] symmetricKey,
byte[] authenticationData,
byte[] encryptedBytes)
throws FfiException
symmetricKey - the symmetric key to useauthenticationData - The associated Data used to authenticate the symmetric encryptionencryptedBytes - the encrypted block bytesFfiException - in case of native library errorpublic MasterKeys generateMasterKeys(Policy policy) throws FfiException
policy - the policy to useFfiException - in case of native library errorpublic byte[] generateUserPrivateKey(byte[] masterPrivateKey,
AccessPolicy accessPolicy,
Policy policy)
throws FfiException
masterPrivateKey - the master private key in bytesaccessPolicy - the access policy of the user private keypolicy - the ABE policyFfiException - in case of native library errorpublic Policy rotateAttributes(Attr[] attributes, Policy policy) throws FfiException, 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 PolicyFfiException - in case of native library errorIOException - standard IO exceptionscom.fasterxml.jackson.databind.DatabindException - standard databind exceptionscom.fasterxml.jackson.core.exc.StreamReadException - stream read exceptionspublic void unwrap(int result)
throws FfiException
result - the result of the FFI callFfiException - in case of native library errorpublic byte[] encrypt(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, byte[] plaintext) throws FfiException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt forplaintext - the plaintext to encryptFfiException - in case of native library errorpublic byte[] encrypt(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, byte[] plaintext, byte[] authenticationData) throws FfiException
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 encryptionFfiException - in case of native library errorpublic byte[] encrypt(Policy policy, byte[] publicKeyBytes, String encryptionPolicy, byte[] plaintext, byte[] additionalData, byte[] authenticationData) throws FfiException
policy - the policy to usepublicKeyBytes - the ABE public key bytesencryptionPolicy - the encryption policy that determines the partitions to encrypt forplaintext - the plaintext to encryptadditionalData - additional data to encrypt and add to the headerauthenticationData - data used to authenticate the symmetric encryptionFfiException - in case of native library errorpublic byte[][] decrypt(byte[] userDecryptionKeyBytes,
byte[] ciphertext)
throws FfiException
userDecryptionKeyBytes - the ABE user decryption key bytesciphertext - the ciphertext to decryptFfiException - in case of native library errorpublic byte[][] decrypt(byte[] userDecryptionKeyBytes,
byte[] ciphertext,
byte[] authenticationData)
throws FfiException
userDecryptionKeyBytes - the ABE user decryption key bytesciphertext - the ciphertext to decryptauthenticationData - data used to authenticate the symmetric encryptionFfiException - in case of native library errorCopyright © 2022. All rights reserved.