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.
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). |
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)..
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.
&Text = &CryptoEncrypt.Decrypt(&EncryptedText) //CryptoEncrypt is of CryptoSymmetricEncrypt type
//Process Errors
msg(format("Error %1 %2", &Cryptoencrypt.ErrCode.ToString(), &Cryptoencrypt.ErrDescription))
In the example below, the text contained in variable &text is encrypted using the Rijndael algorithm.
&CryptoEncrypt= New()
&CryptoEncrypt.BlockSize = 128
&CryptoEncrypt.KeySize = 256
&CryptoEncrypt.Algorithm = CryptoEncryptAlgorithm.Rijndael
&D_text2 = &CryptoEncrypt.Encrypt(&text)
&D_Key = &CryptoEncrypt.Key.ToString()
&IV = &CryptoEncrypt.IV.ToString()
it is important to notice that after the Encrypt method, the developer must save the values of the automatic generated Key and IV to be able to decrypt the text in the future.
- Smart Devices Supported algorithms:
- AES/CBC/NoPadding (128)
- AES/CBC/PKCS5Padding (128)
- AES/ECB/NoPadding (128)
- AES/ECB/PKCS5Padding (128)
- DES/CBC/NoPadding (56)
- DES/CBC/PKCS5Padding (56)
- DES/ECB/NoPadding (56)
- DES/ECB/PKCS5Padding (56)
- DESede/CBC/NoPadding (168)
- DESede/CBC/PKCS5Padding (168)
- DESede/ECB/NoPadding (168)
- DESede/ECB/PKCS5Padding (168)
- RSA/ECB/PKCS1Padding (1024, 2048)
- RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048)
- RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048)
Platform |
Web(.NET,Java), Smart Devices (iOS, Android) |
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.
|