CryptoSymmetricEncrypt data type

Official Content
This documentation is valid for:

Enables the encryption and decryption of text using a symmetrical algorithm (DES, Rijndael, TripleDES), using CBC mode (Cipher Block Chaining). 

The Create method allows us to specify the algorithm used in encrypting the text. This allows us to choose the encryption algorithm without the need to add a new data type.

CryptoSymmetricEncrypt Methods

Name Description
Encrypt(text:String) Encrypts the given text using symmetric cryptography according to the chosen algorithm, the key and the initialization vector (IV).
Decrypt(text:String) Decrypts the given encrypted string using the specified algorithm, the key and the initialization vector (IV).

Properties

Algorithm:CryptoAlgorithmEncrypt   Specifies the encryption algorithm to be used.
Key:String Encryption key must be base-64 encoded. If no key is provided, it is generated automatically upon creating the instance (required when decrypting).
IV:String Encryption initialization vector must be base-64 encoded. If no initialization vector is provided, it is generated automatically upon creating the instance (required when decrypting).
KeySize:Numeric  
BlockSize:Numeric  

Note: The Key and IV (Initialization Vector) properties must be encoded using the Base64 format.
The reason for this requirement is that, internally, the encryption algorithm uses an array of bytes, which cannot always be represented as a String (it can have non-printable characters)..

Example   

A. How to encrypt a text using a symmetrical algorithm.

In the example below, the text contained in variable &text is encrypted using the TripleDES algorithm.

// Make sure to use a String coded as Base64
&CryptoEncrypt.Key ="alNZVUNUc2hxeDBrT3VEczU4TnNoYjFPa1pqN21oMVM=" //CryptoEncrypt is of CryptoSymmetricEncrypt type
&CryptoEncrypt.Algorithm = CryptoEncryptAlgorithm.TripleDES
&result = &CryptoEncrypt.Encrypt(&Text) //The text is encrypted and the result obtained.

B. How to de-encrypt an encrypted text with a symmetrical algorithm.

&Text = &CryptoEncrypt.Decrypt(&EncryptedText) //CryptoEncrypt is of CryptoSymmetricEncrypt type
//Process Errors
msg(format("Error %1 %2", &Cryptoencrypt.ErrCode.ToString(), &Cryptoencrypt.ErrDescription))

Scope

Platform  Web(.NET,Java), Smart Devices (iOS, Android)

Availability

This data type is available as of GeneXus 15.
For Smart Devices enviroment, is available as of Genexus 15 Upgrade 10 for iOS and GeneXus 15 Upgrade 11 for Android.

Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.