ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Encryption/compression functions
  • Compatibility
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Warning
From version 24, UncryptStandard is kept for backward compatibility. This function has been replaced with DecryptStandard.
Decrypts a message that was encrypted with a standard encryption algorithm.
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.
// Encrypt a character string by using the AES algorithm
sMessage is Buffer = "Message to encrypt"
sPassword is ANSI string = "password"
bufKey is Buffer = HashString(HA_MD5_128, sPassword)
bufEncrypt is Buffer = EncryptStandard(sMessage, bufKey, cryptAES128)
// Decryption
bufResult is Buffer = DecryptStandard(bufEncrypt, bufKey, cryptAES128)
Info(bufResult)
Syntax
<Result> = DecryptStandard(<Encrypted message> , <Key> [, <Algorithm> [, <Operation mode> [, <Padding>]]])
<Result>: Binary buffer
  • Result of decryption for the specified message,
  • Empty string ("") if an error occurred. To get more details on the error, use ErrorInfo.
<Encrypted message>: Binary buffer
Message to decrypt. This message can be the encryption result obtained during the call to EncryptStandard.
This buffer must include two sections:
  • The initialization vector (or IV) used to encrypt data.
  • The encrypted data.
If the message was encrypted:
  • by EncryptStandard, this parameter must correspond to the value returned by the function.
  • by an external tool, the buffer must be built by concatenating the encrypted data to initialization vector used.
Note: if the mode of operation specified is encryptsECB, no initialization vector has been used to encrypt the message, and in this case the parameter must correspond directly to the encrypted data.
<Key>: Buffer
Key with which the data was encrypted. This key must be identical to the one supplied when encrypting the message.
<Algorithm>: Optional Integer constant
Encryption algorithm used. This parameter must correspond to the algorithm used to encrypt the message.
crypt3DESTriple 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 2025
cryptAES192
Advanced Encryption Standard.
  • Key size: 192 bits.
  • Block size: 128 bits.
  • Initialization vector (IV) size: 128 bits.
AndroidAndroid Widget JavaPHP This constant is not available.
cryptAES256Advanced Encryption Standard.
  • Key size: 256 bits.
  • Block size: 128 bits.
  • Initialization vector (IV) size: 128 bits.
cryptDESData 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 used. This parameter must correspond to the operation mode used to encrypt the message.
cryptCBC
(Default value)
Cipher Block Chaining - Sequence of blocks.
cryptCFBCipher Feedback - Feedback encryption.
New in version 2025
From now on, this processing mode is available regardless of the algorithm used.
AndroidAndroid Widget JavaPHP This constant is not available.
cryptCTRCipher Counter - Encryption based on a counter.
New in version 2025
From now on, this processing mode is available regardless of the algorithm used.
AndroidAndroid Widget JavaPHP This constant is not available.
cryptECBElectronic Code Book - Dictionary of codes. This mode of operation is not recommended and should only be used for compatibility reasons.
<Padding>: Optional Integer constant
Padding mode for encrypted data to be compatible with the size required by block encryption algorithms. This parameter must correspond to the fill mode used to encrypt the message.
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.
Remarks

Compatibility

The old Encrypt and Decrypt functions used a proprietary internal encryption format.. A string encrypted using the Encrypt algorithm cannot therefore be decrypted using the usual algorithms accessed by the DecryptStandard function.
To change your encryption solution, you must:
  1. decrypt all current encrypted data (function Decrypt)
  2. encrypt this data with function EncryptStandard and a new algorithm.
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: wd300com.dll
Minimum version required
  • Version 20
This page is also available for…
Comments
Exemplo com Fonte
https://repository.windev.com/resource.awp?file_id=281474976711928;exemplo-cryptografia-descryptografia
Boller
15 Mar. 2024
OBS
É muito importante fazer o encode e o decode base 64 quando usar em arquivos de texto ou arquivos ini, pois existe varios formatos de arquivos sendo eles: ansi, unicode, utf-8. E uma vez encodado e decodando a criptofrafia e descriptografia vai funcionar perfeitamente pois os caracteres originais estaram cifrados, se nao fazer o encode e decode os caracteres armazenados nao vao bater e a senha usada sera inutil e nao dara certo o procedimento.

Il est très important d'encoder et de décoder la base 64 lors de l'utilisation de fichiers texte ou de fichiers ini, car il existe plusieurs formats de fichiers : ansi, unicode, utf-8. Et une fois encodés et décodés, le cryptage et le décryptage fonctionneront parfaitement car les caractères originaux seront cryptés, si vous n'encodez pas et ne décodez pas les caractères stockés ne correspondront pas et le mot de passe utilisé sera inutile et la procédure ne fonctionnera pas.

It is very important to encode and decode base 64 when using text
Boller
15 Mar. 2024
Exemplo 1
E no Windev Mobile
//Criptografia
buf_conteudo_sig is Buffer = "Meu nome é Adriano Boller"
B_senha is Buffer = HashString(HA_HMAC_MD5_128, "bob-esponja")
B_resultado_Criptografado is Buffer = CryptStandard(buf_conteudo_sig, B_senha, cryptAES128)
B_resultado_Criptografado=Encode(B_resultado_Criptografado, encodeBASE64)

Info(B_resultado_Criptografado)


//Descriptografia
B_senha = HashString(HA_HMAC_MD5_128, "bob-esponja")
B_resultado_Descriptografado is Buffer = Decode(B_resultado_Criptografado, encodeBASE64)
B_resultado_Descriptografado = UncryptStandard(B_resultado_Descriptografado, B_senha, cryptAES128)

Info(B_resultado_Descriptografado )
Boller
15 Mar. 2024
Exemplo 2
Example
//Exemplo para Criptografar
// se usar a criptografia em um arquivo texto ou ini deve fazer encode 64 bits.

sMessage is Buffer = "Message to encrypt"
bufKey is Buffer = HashString(HA_CKSUM_64, "password")
bufEncrypt is Buffer = CryptStandard(sMessage, bufKey, cryptDES)
bufEncrypt = Encode(bufEncrypt, encodeBASE64)
Info(bufEncrypt)

// Exemplo para Decriptografar
bufKey = HashString(HA_CKSUM_64, "password")
sResult is Buffer = Decode(bufEncrypt, encodeBASE64)
sResult = UncryptStandard(sResult, bufKey, cryptDES)
Info(sResult)
Boller
15 Mar. 2024

Last update: 09/30/2024

Send a report | Local help