Description
Decrypts a blob value using symmetric algorithm.
Applies to
CrypterObject objects
Syntax
crypter.SymmetricDecrypt(SymmetricAlgorithm algorithm, Blob variable, Blob key{, OperationMode operationmode{, Blob iv{, PaddingScheme padding{, Blob aad}}}})
|
Argument |
Description |
|---|---|
|
crypter |
The name of the CrypterObject object. |
|
algorithm |
A value of the SymmetricAlgorithm enumerated type that specifies the type of symmetric algorithm. Values are:
|
|
variable |
A blob whose value is the data you want to decrypt with symmetric algorithm. When using the system blob function to convert a string to a blob, it is recommended to specify its encoding argument to be EncodingANSI! (for English characters only) or EncodingUTF8!, otherwise, the default EncodingUTF16LE! will be used. |
|
key |
A blob specifying the secret key. The length of the secret key can be 128 bits, 192 bits, 256 bits with AES or AES_GCM. The length of the secret key must be 64 bits with DES. The length of the secret key can be 128 bits, 192 bits with TDES. The length of the secret key must be 192 bits with DESX. The length of the secret key can be 32 bits~448 bits with Blowfish. |
|
operationmode (optional) |
A value of the OperationMode enumerated type that specifies the mode of operation. Values are:
|
|
iv (optional) |
A blob specifying the initialization vector. Zeros filled by default. In the AES algorithm, the effective length of iv is 16 bytes, in the AES_GCM algorithm, the effective length of iv is 12 bytes, and the others are 8 bytes. If the length is not enough, it will be automatically filled with zeros. In the ECB operation mode, the iv will be ignored. |
|
padding (optional) |
A value of the PaddingScheme enumerated type that specifies the padding schemes used for block cipher. Values are:
ZerosPadding!, PKCSPadding!, and OneAndZerosPadding! can be used with ECB and CBC operation mode. NoPadding! can be used with CFB, OFB and CTR operation mode. |
|
aad (optional) |
A blob specifying the additional authenticated data. aad argument takes effect only when algorithm is AES_GCM!. |
Return value
Blob.
Returns the result of the decrypt if it succeeds. If any argument's value is null, the method returns null. If an error occurs, throw the exception.
Examples
The following statements encrypt the data using AES and then decrypt the data using AES.
Blob lblb_data
Blob lblb_key
Blob lblb_iv
Blob lblb_encrypt
Blob lblb_decrypt
lblb_data = Blob("Test AES", EncodingANSI!)
lblb_key = Blob("Test Key12345678", EncodingANSI!)
lblb_iv = Blob("Test IV 12345678", EncodingANSI!)
CrypterObject lnv_CrypterObject
lnv_CrypterObject = Create CrypterObject
// Encrypt data using AES
lblb_encrypt = lnv_CrypterObject.SymmetricEncrypt(AES!, lblb_data, lblb_key, &
OperationModeCBC!, lblb_iv, PKCSPadding!)
// Decrypt data using AES
lblb_decrypt = lnv_CrypterObject.SymmetricDecrypt(AES!, lblb_encrypt, lblb_key, &
OperationModeCBC!, lblb_iv, PKCSPadding!)
messagebox("SymmetricDecrypt", string(lblb_decrypt, EncodingANSI!))The following statements encrypt the data using AES_GCM and then decrypt the data using AES_GCM.
Blob lblb_data
Blob lblb_key
Blob lblb_iv
Blob lblb_add
Blob lblb_encrypt
Blob lblb_decrypt
CoderObject lco_Code
lco_Code = create CoderObject
CrypterObject lnv_CrypterObject
lnv_CrypterObject = Create CrypterObject
lblb_data = Blob("TestAppeon", EncodingUTF16BE!)
lblb_key = Blob("Test Key12345678", EncodingUTF16BE!)
lblb_iv = Blob("Test IV 12345678", EncodingUTF16BE!)
lblb_add = Blob("Testadd", EncodingUTF16BE!)
//aad argument takes effect only when algorithm is AES_GCM!
lblb_encrypt = lnv_CrypterObject.SymmetricEncrypt(AES_GCM!, lblb_data, lblb_key,OperationModeCTR! , lblb_iv, DefaultPadding!,lblb_add)
//decrypt
lblb_decrypt = lnv_CrypterObject.SymmetricDecrypt(AES_GCM!, lblb_encrypt, lblb_key,OperationModeCTR!, lblb_iv, DefaultPadding!,lblb_add )
messagebox("SymmetricDecrypt return value ",string(lblb_decrypt, EncodingUTF16BE!))
destroy lco_Code
destroy lnv_CrypterObject
See also


