CryptoDataUtility
CryptoDataUtility allows the user to decrypt a string without specifying the keyName and algorithm. To accomplish this, the ciphertext, at the time of encryption, is bundled with the same metadata, of the key, which was used for encryption.
On installing the CADP for .NET Core (64 bit or 32 bit), the CryptoDataUtility.dll
gets placed in the C:\Users\user profile\.nuget\packages\ciphertrust.cadp.netcore\<latest version>\utility
folder. The user must explicitly add reference of CryptoDataUtility.dll to the application.
SymmetricEncryptionUtility Class
This class is a thread-safe utility class to encrypt/decrypt data and bundle it with it's associated metadata. In case the user does not specify any IV during encryption, this class auto-generates the IV.
Note
Only AES/CBC/PKCS7Padding is supported by this class.
Supported Algorithms
Currently, this utility supports only AES algorithm.
Supported APIs
public SymmetricEncryptionUtility(NaeSession session);
Constructor that takes NaeSession object to retrieve keys from the CipherTeust Manager.
public byte[] Encrypt(byte[] plaintext, String keyName);
Encrypts the given plaintext with the given key. It auto-generates the IV and uses the default cipher and padding modes (CBC/PKCS7Padding).
public byte[] Encrypt(byte[] plaintext, String keyName, byte[] iv);
Encrypts the given plaintext with the given key. It uses the default cipher and padding modes (CBC/PKCS7Padding).
public byte[] Encrypt(byte[] plaintext, String keyName, CipherMode mode, PaddingMode padding, byte[] iv);
Encrypts the given plaintext with the given parameters.
Note
Encrypt API returns the bundled ciphertext, that is, ciphertext with key metadata.
public byte[] Decrypt(byte[] bundledCipherText);
Decrypts the given bundled ciphertext byte array.
Note
This method can only decrypt data that has been generated by the Encrypt API of this class.
For samples, refer to Github.