SymmetricEncrypt

Description

Encrypts a blob value using symmetric algorithm.

Applies to

CrypterObject objects

Syntax

crypter.SymmetricEncrypt ( algorithm, variable, key{, operationmode{, iv{, padding}}})

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:

  • AES! – The Advanced Encryption Standard

  • DES! – The Data Encryption Standard

  • TDES! – The Triple-DES

  • DESX! – The DES-XEX3

  • Blowfish! – The Blowfish

variable

A blob whose value is the data you want to encrypt 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.

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:

  • OperationModeECB! – (Default) The Electronic Codebook (ECB) mode

  • OperationModeCBC! – The Cipher Block Chaining (CBC) mode

  • OperationModeCFB! – The Cipher Feedback (CFB) mode

  • OperationModeOFB! – The Output Feedback (OFB) mode

  • OperationModeCTR! – The Counter (CTR) mode

iv (optional)

A blob specifying the initialization vector. Zeros filled by default. In the AES algorithm, the effective length of the iv is 16 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:

  • NoPadding! – No padding added to a block

  • ZerosPadding! – 0's padding added to a block

  • PKCSPadding! – PKCS #5 padding added to a block

  • OneAndZerosPadding! – 1 and 0's padding added to a block

  • DefaultPadding! – (Default) Default padding scheme. DefaultPadding! means PKCSPadding! for ECB or CBC mode. Otherwise, NoPadding! for modes like CFB, OFB, and CTR.

ZerosPadding!, PKCSPadding!, and OneAndZerosPadding! can be used with ECB and CBC operation mode. NoPadding! can be used with CFB, OFB and CTR operation mode.


Return value

Blob.

Returns the encryption result (length: 24) 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 return the encrypted data.

Blob lblb_data
Blob lblb_key
Blob lblb_iv
Blob lblb_encrypt

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

lblb_encrypt = lnv_CrypterObject.SymmetricEncrypt(AES!, lblb_data, lblb_key, &
	OperationModeCBC!, lblb_iv, PKCSPadding!)

See also

SymmetricDecrypt

AsymmetricEncrypt

AsymmetricDecrypt

AsymmetricSign

AsymmetricVerifySign

AsymmetricGenerateKey

MD5

SHA

HMAC