PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Results obtained with AES encryption
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Warning
From version 24, CryptStandard is kept for backward compatibility. This function is replaced by 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.
Remark: The first call to EncryptStandard can be quite long because the randomization must be initialized.
// Encrypt a character string by using the AES algorithm
// ------------------------------------------------------------------
bufMessage is Buffer = "Message to encrypt"
bufKey is Buffer = HashString(HA_MD5_128, "password")
bufEncrypt is Buffer = EncryptStandard(sMessage, bufKey, cryptAES128)
 
// Decrypt in WLanguage
-------------------------
bufResult is Buffer = DecryptStandard(bufEncrypt, bufKey, cryptAES128)
Info(sResult)
// Encryption in WLanguage
// ---------------------
bufMessage is Buffer = "Message to encrypt"
bufKey is Buffer = HashString(HA_MD5_128, "password")
bufEncrypt is Buffer = EncryptStandard(sMessage, bufKey, cryptAES128)
 
//---------------------------------------------------------------
// Decrypt via a call to the Mcrypt API of PHP
nSizeIV is int = 128 / 8
bufIV is Buffer = bufEncrypt[[ TO nSizeIV]]
bufData is Buffer = bufEncrypt[[nSizeIV+1 TO]]
 
EXTERN mcrypt_decrypt//PHP API (to be done in a WEBDEV PHP server process)
Trace(mcrypt_decrypt( "rijndael-128", bufKey, bufData, "cbc", bufIV))
Syntax
<Result> = EncryptStandard(<Message> , <Key> [, <Algorithm> [, <Operation mode> [, <Fill> [, <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).
Remark: If the specified mode is cryptECB, no initialization vector is used, and in this case the function returns the 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 handle character string, the same format must be used on all the 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:
crypt3DESTriple Data Encryption Standard.
  • Size of key: 192 bits.
  • Size of blocks: 64-bit.
  • Size of initialization vector (IV): 64-bit.
cryptAES128
(Default value)
Advanced Encryption Standard.
  • Size of key: 128 bits.
  • Size of blocks: 128 bits.
  • Size of initialization vector (IV): 128 bits.
cryptAES256Advanced Encryption Standard.
  • Size of key: 256 bits.
  • Size of blocks: 128 bits.
  • Size of initialization vector (IV): 128 bits.
cryptDESData Encryption Standard.
  • Size of key: 64-bit.
  • Size of blocks: 64-bit.
  • Size of initialization vector (IV): 64-bit.
Caution: 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
cryptCFBCipher Feedback - Feedback encryption. This process mode is available if the algorithm used corresponds to the cryptAES256 constant.
AndroidAndroid Widget JavaPHP This constant is not available.
cryptCTRCipher Counter - Encryption based on a counter. This process mode is available if the algorithm used corresponds to the cryptAES256 constant.
AndroidAndroid Widget JavaPHP This constant is not available.
cryptECBElectronic Code Book - Dictionary of codes. This operation mode is not recommended and it should only be used for compatibility reasons.
No initialization vector is used, and in this case the function returns the encrypted data directly.
<Fill>: Optional Integer constant
Mode for filling the encrypted data in order to be compatible with the size required by the encryption algorithms by blocks:
cryptPaddingPKCS
(Default value)
The data is filled with bytes whose value corresponds to the total number of bytes added to reach the requested size.
cryptPaddingZeroThe data is filled with binary zeros until the requested size is reached.
<Initialization vector>: Optional buffer
New in version 27
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.
Caution: This parameter should only be used if you need a custom initialization vector in your project. Otherwise, it is strongly advised to keep the generation of the initialization vector in random mode.
PHP This parameter is not available.
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:
The encryption functions 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
Component: wd270com.dll
Minimum version required
  • Version 20
This page is also available for…
Comments
Valida Criptografia e Descriptografia
//Chave valida sem caracteres especiais ASCII invisiveis e sem espaços em branco ou quebras de linha


loop
resultado = criaChave(valor) //cria a chave usando cryptstandar
if valida(resultado) = true //valida regras
break // se ok para de criar
end
end
BOLLER
09 May 2018
How to actually work between WD/WM/WB
https://forum.pcsoft.fr/en-US/pcsoft.us.windevmobile/2019-wm20-w20-uncryptstandard-cryptstandard/read.awp?hl=*
Jose
25 Apr. 2018
Example
//Exemplo para Criptografar
sMessage is Buffer = "Message to encrypt"
bufKey is Buffer = HashString(HA_CKSUM_64, "password")
bufEncrypt is Buffer = CryptStandard(sMessage, bufKey, cryptDES)

Info(bufEncrypt)

// Exemplo para Decriptografar
bufKey is Buffer = HashString(HA_CKSUM_64, "password")
sResult is Buffer = UncryptStandard(bufEncrypt, bufKey, cryptDES)

Info(sResult)



//E no Windev Mobile
//Criptografia
B_senha is Buffer = HashString(HA_HMAC_MD5_128, "bob-esponja")
B_resultado_Criptografado is Buffer = CryptStandard(buf_conteudo_sig, B_senha, cryptAES128)

info(B_resultado_Criptografado)


//Descriptografia
B_senha is Buffer = HashString(HA_HMAC_MD5_128, "bob-esponja")
B_resultado_Descriptografado is Buffer = UnCryptStandard(buf_conteudo_sig, B_senha, cryptAES128)

info(B_resultado_Descriptografado )
BOLLER
16 Mar. 2018