encrypt()
Encrypts the given plaintext using the specified passphrase and configuration.
Synopsis
int encrypt(string | blob plaintext, string passphrase, blob ciphertext [,
string cipherConfig]);
Parameters
Parameter | Description |
---|---|
plaintext | The plaintext to encrypt. |
passphrase | The passphrase to use for encryption. |
ciphertext | The object to store the encrypted data. |
config | The encryption configuration to use (default is
"AES_256_CBC__HMAC_SHA_3_256__PBKDF2_SHA_3_256__100000 ").
You can use user-defined configurations. To do this, use a character string in a specific format that is understandable for the CCL. The format for the cipher configuration is defined as follows: <CipherAlgorithm>__<CipherHmacAlgorithm>__<CipherKeyDerivationFunction>__<KeyIterationCount>Currently you can only configure the KeyIterationCount, so two customizable configurations are possible: AES_256_CBC__HMAC_SHA_3_256__PBKDF2_SHA_3_256__<KeyIterationCount> ENVELOPE_RSA_AES_256_CBC__HMAC_SHA_3_256__PBKDF2_SHA_3_256__<KeyIterationCount> |
ErrorCode | Indicates the success or failure of the operation. In the event of an error, the function returns negative values. Otherwise, the length of the resulting blob is returned in bytes. |
Return Value
Indicates the success or failure of the operation. In the event of an error, the function returns negative values. Otherwise, the length of the resulting blob is returned in bytes.
Description
This method encrypts the specified plaintext data using the specified passphrase and the cipher configuration and stores the result in the specified ciphertext.
Example
public int test_AES_256_CBC_EncryptDecrypt_String()
{
const string plaintext = "Test encryption and decryption. Тест русских символов.";
const string passphrase = "akaSpUk0agC1P3f 测试中文字符和特殊字符";
const string cipherConfig = "AES_256_CBC__HMAC_SHA_3_256__PBKDF2_SHA_3_256__123456";
blob ciphertext;
int errorCode = encrypt(plaintext, passphrase, ciphertext, cipherConfig);
this.assertEqual(errorCode, 176);
string decryptedText;
errorCode = decrypt(ciphertext, passphrase, decryptedText);
return 0;
}