|
|
|
|
|
- Results obtained with AES encryption
EncryptStandard (Function) In french: CrypteStandard
Warning
From version 24, CryptStandard is kept for backward compatibility. This function has been replaced with EncryptStandard.
Encrypts a character string or a binary buffer by using a symmetrical encryption algorithm (AES, DES, etc.). This encrypted message can be decrypted by DecryptStandard. Unlike Encrypt and Decrypt, EncryptStandard and DecryptStandard use the standard encryption algorithms that allow you to exchange encrypted messages between different runtime platforms (Windows, Linux, Android, Java, iOS, PHP, etc.) and/or with external tools. Note: The first call to the EncryptStandard function can be relatively long, as it is necessary to initialize randomization..
bufMessage is Buffer = "Message à crypter"
bufClé is Buffer = HashChaîne(HA_MD5_128, "mot de passe")
bufCrypte is Buffer = CrypteStandard(bufMessage, bufClé, cryptAES128)
-------------------------
bufRésultat is Buffer = DécrypteStandard(bufCrypte, bufClé, cryptAES128)
Info(bufRésultat)
bufMessage is Buffer = "Message à crypter"
bufClé is Buffer = HashChaîne(HA_MD5_128, "ma chaîne à crypter")
bufCrypte is Buffer = CrypteStandard(bufMessage, bufClé, cryptAES128)
nTailleIV is int = 128 / 8
bufIV is Buffer = bufCrypte[[ TO nTailleIV]]
bufDonnées is Buffer = bufCrypte[[nTailleIV+1 TO]]
EXTERN mcrypt_decrypt
Trace(mcrypt_decrypt("rijndael-128", bufClé, bufDonnées, "cbc", bufIV))
Syntax
<Result> = EncryptStandard(<Message> , <Key> [, <Algorithm> [, <Operation mode> [, <Filling> [, <Initialization vector>]]]])
<Result>: Binary buffer - Result of encryption for the specified message,
- Empty string ("") if an error occurred. To get more details on the error, use ErrorInfo.
This buffer includes two sections: - The initialization vector (IV) which corresponds to a randomly generated block of bits (or specified with <Initialization vector>) that has been combined with the first block of encrypted data. This vector is required to allow the message decryption. Its size corresponds to the size of blocks used by the encryption algorithm (see the <Algorithm> parameter).
- The encrypted data.
If the message must be decrypted: - by DecryptStandard, all you have to do is pass the entire buffer to the function.
- by an external tool, the buffer must be split to separate the initialization vector from the encrypted data (see the example).
Note: If the mode of operation specified is cryptsECB, no initialization vector is used and the function returns encrypted data directly.
<Message>: Binary buffer Message to encrypt. <Key>: Buffer Key with which the data must be encrypted. The size of this key depends on the encryption algorithm used. The key size must correspond to the one of the algorithm. We recommend that you use the hashing functions ( HashString for example) to create a key from a password. A long password that includes several alphanumeric characters and distinct symbols provides better encryption security. Cross-platform development: To manipulate strings, you need to use the same format on all platforms. We advise you to use strings in UTF 8 format (and to convert the Unicode strings if necessary). <Algorithm>: Optional Integer constant Encryption algorithm to use: | | crypt3DES | Triple Data Encryption Standard. - Key size: 192 bits.
- Block size: 64 bits.
- Initialization vector (IV) size: 64 bits.
| cryptAES128 (Default value) | Advanced Encryption Standard. - Key size: 128 bits.
- Block size: 128 bits.
- Initialization vector (IV) size: 128 bits.
| New in version 2025cryptAES192 | Advanced Encryption Standard. - Key size: 192 bits.
- Block size: 128 bits.
- Initialization vector (IV) size: 128 bits.
| cryptAES256 | Advanced Encryption Standard. - Key size: 256 bits.
- Block size: 128 bits.
- Initialization vector (IV) size: 128 bits.
| cryptDES | Data Encryption Standard. - Key size: 64 bits.
- Block size: 64 bits.
- Initialization vector (IV) size: 64 bits.
Warning: this algorithm is currently deprecated. |
<Operation mode>: Optional Integer constant Process mode of blocks by the encryption algorithm: | | cryptCBC (Default value) | Cipher Block Chaining - Sequence of blocks | cryptCFB | Cipher Feedback - Feedback encryption. New in version 2025From now on, this processing mode is available regardless of the algorithm used. | cryptCTR | Cipher Counter - Encryption based on a counter. New in version 2025From now on, this processing mode is available regardless of the algorithm used. | cryptECB | Electronic Code Book - Dictionary of codes. This mode is not recommended and should only be used for compatibility reasons. No initialization vector is used, and in this case the function returns the encrypted data directly. |
<Filling>: Optional Integer constant Padding mode for encrypted data to be compatible with the size required by block encryption algorithms: | | cryptPaddingPKCS (Default value) | The data is filled with bytes whose value corresponds to the total number of bytes added to reach the requested size. | cryptPaddingZero | The data is filled with binary zeros until the requested size is reached. |
<Initialization vector>: Optional buffer Initialization vector (IV) to be used for encryption. The size of the buffer depends on the encryption algorithm (<Algorithm< parameter). If this parameter is not specified, the initialization vector is randomly generated. Warning: This parameter should only be used if you need a custom initialization vector in yourproject. . Otherwise, it is strongly advised to keep the generation of the initialization vector in random mode. Remarks Results obtained with AES encryption Encryption performed with an AES algorithm uses an initialization vector. This initialization vector is modified each time the function is called. It is therefore normal to get a different result each time the same information is encrypted. However, the expected value is correctly retrieved when DecryptStandard is called.
Related Examples:
|
Unit examples (WINDEV): The encryption functions
[ + ] Using the encryption/decryption functions of WINDEV. This example is used to: - Encrypt a character string - Decrypt a character string
|
Business / UI classification: Business Logic
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|