PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Encrypts a character string or a binary buffer by using a symmetrical encryption algorithm (AES, DES, etc.). This encrypted message can be decrypted by UncryptStandard.
Unlike Crypt and Uncrypt, CryptStandard and UncryptStandard 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 CryptStantard can be quite long because the randomization must be initialized.
WEBDEV - Server codePHP This function is available for the PHP sites from version 200051.
// Encrypt a character string by using the AES algorithm
// ------------------------------------------------------------------
sMessage is Buffer = "Message to encrypt"
bufKey is Buffer = HashString(HA_MD5_128, "password")
bufEncrypt is Buffer = CryptStandard(sMessage, bufKey, cryptAES128)

// Decrypt in WLanguage
-------------------------
sResult is Buffer = UncryptStandard(bufEncrypt, bufKey, cryptAES128)
Info(sResult)
// Crypt in WLanguage
// ---------------------
sMessage is Buffer = "Message to encrypt"
bufKey is Buffer = HashString(HA_MD5_128, "password")
bufEncrypt is Buffer = CryptStandard(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]]

EXTERNE mcrypt_decrypt//PHP API (to be done in a WEBDEV PHP server process)
Trace(mcrypt_decrypt( "rijndael-128", bufKey, bufData, "cbc", bufIV))
Syntax
<Result> = CryptStandard(<Message> , <Key> [, <Algorithm> [, <Operation Mode> [, <Filling>]]])
<Result>: Binary buffer
  • Result of encryption for the specified message,
  • Empty string ("") if an error occurred. To find out the error details, use ErrorInfo.
This buffer includes two sections:
  • The initialization vector (or IV) that corresponds to the block of bits generated at random and that was combined to 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 UncryptStandard, 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 specified operation 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.
Multi-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:
cryptAES128
(Default value)
Advanced Encryption Standard.
  • Size of key: 128 bits.
  • Size of blocks: 128 bits.
  • Size of initialization vector (IV): 128 bits.
Versions 23 and later
cryptAES256
New in version 23
cryptAES256
cryptAES256
Advanced Encryption Standard.
  • Size of key: 256 bits.
  • Size of blocks: 128 bits.
  • Size of initialization vector (IV): 128 bits.
AndroidAndroid Widget JavaPHP This constant is not available.
cryptDESData Encryption Standard.
  • Size of key: 64 bits.
  • Size of blocks: 64 bits.
  • Size of initialization vector (IV): 64 bits.
crypt3DESTriple Data Encryption Standard.
  • Size of key: 192 bits.
  • Size of blocks: 64 bits.
  • Size of initialization vector (IV): 64 bits.
<Operation Mode>: Optional Integer constant
Process mode of blocks by the encryption algorithm:
cryptCBC
(Default value)
Cipher Block Chaining - Sequence of blocks
Versions 23 and later
cryptCFB
New in version 23
cryptCFB
cryptCFB
Cipher 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.
Versions 23 and later
cryptCTR
New in version 23
cryptCTR
cryptCTR
Cipher 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.
<Filling>: 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.
Related Examples:
The Crypt functions Unit examples (WINDEV): The Crypt functions
[ + ] Using the encryption/decryption functions of WINDEV.
This example is used to:
- Encrypt a character string
- Decrypt a character string
Components
WINDEVWEBDEV - Server codeReports and Queries wd230com.dll
Java wd230java.jar
Linux wd230com.so
Android wd230android.jar
Minimum required version
  • 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
May 09 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
Apr. 25 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
Mar. 16 2018