AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de cifrado/compresión
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
Encrypts a buffer using an asymmetric encryption algorithm (RSA) that requires a public key and a private key.
This encrypted message can be decrypted:
Example
// Encrypting a character string
// ---------------------------------------
bufToEncrypt is Buffer = "Message to encrypt"
bufEncryptedMessage is Buffer
sPublicKeyFile is string = fExeDir() + "\PublicKey.pem"
sPublicKeyPassword is string = "xxx"
 
bufEncryptedMessage = bufToEncrypt.EncryptAsymmetric(sPublicKeyFile, ...
sPublicKeyPassword, cryptPaddingPKCS1)
 
// Decryption  
// -------------
bufEncryptedMessage is Buffer
bufDecryptedMessage is Buffer
sPrivateKeyFile is string = fExeDir() + "\PrivateKey.pem"
sPrivateKeyPassword is string = "xxx"
 
bufDecryptedMessage = bufEncryptedMessage.DecryptAsymmetric(sPrivateKeyFile, ...
sPrivateKeyPassword, cryptPaddingPKCS1)
bufToEncrypt is Buffer = StringToUTF8("สวัสดี Test")
bufPrivateKey is Buffer
bufPublicKey is Buffer
(bufPrivateKey, bufPublicKey) = EncryptGenerateRSAKey(1024)
// Encryption
bufEncrypted is Buffer = bufToEncrypt.EncryptAsymmetric(bufPublicKey)
bufSign is Buffer = CertificateSignString(bufEncrypted, bufPrivateKey, "", ...
certSignatureOnly + certSHA256)
// Decryption
IF CertificateCheckString(bufEncrypted, bufSign, bufPublicKey, "", "", ...
certSignatureOnly + certSHA256) THEN
bufReadable is Buffer = bufEncrypted.DecryptAsymmetric(bufPrivateKey)
Trace("Authentic message")
Trace(bufReadable.UTF8ToString())
ELSE
Trace("Unauthenticated message")
END
Syntax
<Result> = <Content to encrypt>.EncryptAsymmetric(<Public key file> [, <Password> [, <Padding>]])
<Result>: Character string or Buffer
Result of encryption for the specified message.
<Content to encrypt>: Buffer
Buffer to encrypt.
Caution: The size of the message to be encrypted must be smaller than the size of the key minus the minimum padding size (11 bytes for PKCS1 and 41 for OAEP).
For example, for a 4096-bit key and OAEP padding, the message cannot exceed 471 bytes.
<Public key file>: Character string or Buffer
  • Name and path of the file corresponding to the public key that will be used to encrypt. pem, der and p12 key formats are supported.
  • Buffer containing the public key that will be used for the encryption.
<Password>: Optional character string
Key file password (if required).
<Padding>: Optional Integer constant
Padding mode of encrypted data to be compatible with the size required by the encryption algorithms by blocks:
cryptPaddingOAEPPadding according to the OAEP algorithm (Optimal Asymmetric Encryption Padding).
cryptPaddingPKCS1
(Default value)
Padding according to the PKCS 1 algorithm (Public Key Cryptographic Standards).
Business / UI classification: Business Logic
Component: wd290com.dll
Versión mínima requerida
  • Versión 26
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 21/06/2023

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