AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de cifrado/compresión
  • Results obtained with AES encryption
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Advertencia
A partir de la versión 24, CryptStandard se conserva por motivos de compatibilidad. Esta función ha sido reemplazada por 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..
// 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(bufMessage, bufKey, encryptAES128)

// Decrypt in WLanguage
------------------------- 
bufResult is Buffer = DecryptStandard(bufEncrypt, bufKey, encryptAES128)
Info(bufResult)
// Encryption in WLanguage
// ---------------------
bufMessage is Buffer = "Message to encrypt"
bufKey is Buffer = HashString(HA_MD5_128, "string to encrypt")
bufEncrypt is Buffer = EncryptStandard(bufMessage, bufKey, encryptAES128)

//---------------------------------------------------------------
// 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))
Sintaxis
<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 operating mode specified is crypteECBno initialization vector is used, in which case the function returns encrypted data directly.
<Message>: Binary buffer
Message to encrypt.
<Key>: Buffer or Secret string
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).
Novedad versión 2025
Cadenas secretas: Si utiliza el almacén de cadenas secretas, el tipo de cadena secreta utilizado para este parámetro puede ser "Buffer - ASCII" o "Buffer - UTF-8".
Para obtener más información sobre las cadenas secretas y el almacén, consulte Almacén de cadenas secretas.
Novedad versión 2025
AndroidWidget Android Las cadenas secretas no están disponibles para este parámetro en aplicaciones Android y widgets de Android.
<Algorithm>: Optional Integer constant
Encryption algorithm to use:
Novedad versión 2025
cryptAES192
Advanced Encryption Standard.
  • Key size: 192 bits.
  • Block size: 128 bits.
  • Initialization vector (IV) size: 128 bits.
PHP This constant is not available.
encrypt3DESTriple Data Encryption Standard.
  • Key size: 192 bits.
  • Block size: 64 bits.
  • Initialization vector (IV) size: 64 bits.
encryptAES128
(Default value)
Advanced Encryption Standard.
  • Key size: 128 bits.
  • Block size: 128 bits.
  • Initialization vector (IV) size: 128 bits.
encryptAES256Advanced Encryption Standard.
  • Key size: 256 bits.
  • Block size: 128 bits.
  • Initialization vector (IV) size: 128 bits.
encryptDESData 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:
encryptCBC
(Default value)
Cipher Block Chaining - Sequence of blocks
encryptCFBCipher Feedback - Feedback encryption.
Novedad versión 2025
From now on, this processing mode is available regardless of the algorithm used.
AndroidWidget Android JavaPHP This constant is not available.
encryptCTRCipher Counter - Encryption based on a counter.
Novedad versión 2025
From now on, this processing mode is available regardless of the algorithm used.
AndroidWidget Android JavaPHP This constant is not available.
encryptECBElectronic 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:
encryptPaddingPKCS
(Default value)
The data is filled with bytes whose value corresponds to the total number of bytes added to reach the requested size.
encryptPaddingZeroThe 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.
PHP This parameter is not available.
Observaciones

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.
Clasificación Lógica de negocio / UI: Lógica de negocio
Componente: wd300com.dll
Versión mínima requerida
  • Versión 20
Esta página también está disponible para…
Comentarios
Exemplo com EncryptStandart e DecryptStandard
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 =
EncryptStandard(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 = DecryptStandard(sResult, bufKey, cryptDES)
Info(sResult)
Boller
14 04 2025
Exemplo com Fonte
https://repository.windev.com/resource.awp?file_id=281474976711928;exemplo-cryptografia-descryptografia
Boller
15 03 2024
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 03 2024
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 03 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.
Boller
15 03 2024
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 05 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 04 2018

Última modificación: 16/05/2025

Señalar un error o enviar una sugerencia | Ayuda local