ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Encryption/compression functions
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
Decrypts a buffer with a private/public key algorithm with RSA encryption. The data has been previously encrypted with <Buffer type>.EncryptAsymmetric.
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 decrypt>.DecryptAsymmetric(<Private key file> [, <Password> [, <Padding>]])
<Result>: Buffer
Decrypted data.
<Content to decrypt>: Buffer
Buffer to decrypt.
<Private key file>: Character string or Buffer
  • Name and path of the file corresponding to the RSA private key to be used to decrypt the data. pem and p12 key formats are supported.
  • Buffer containing the RSA private key to be used to decrypt the data.
<Password>: Optional character string
Key file password (if required).
<Padding>: Optional Integer constant
Padding mode for encrypted data (used during encryption) to be compatible with the size required by block encryption algorithms:
cryptPaddingOAEPPadding according to the OAEP algorithm (Optimal Asymmetric Encryption Padding).
cryptPaddingPKCS1
(Default value)
Padding according to the PKCS 1 algorithm (Public Key Cryptographic Standards).
Component: wd290com.dll
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/21/2023

Send a report | Local help