|
|
|
|
|
EncryptAsymmetric (Function) In french: CrypteAsymétrique Encrypts a buffer using an asymmetric encryption algorithm (RSA) that requires a public key and a private key. This encrypted message can be decrypted: - with the DecryptAsymmetric function.
- with third-party software (using the same padding options).
bufToEncrypt is Buffer = "Message to encrypt"
bufEncryptedMessage is Buffer
sPublicKeyFile is string = fExeDir() + "\PublicKey.pem"
sPublicKeyPassword is string = "xxx"
bufEncryptedMessage = EncryptAsymmetric(bufToEncrypt, sPublicKeyFile, ...
sPublicKeyPassword, cryptPaddingPKCS1)
bufEncryptedMessage is Buffer
bufDecryptedMessage is Buffer
sPrivateKeyFile is string = fExeDir() + "\PrivateKey.pem"
sPrivateKeyPassword is string = "xxx"
bufDecryptedMessage = DecryptAsymmetric(bufEncryptedMessage, sPrivateKeyFile, ...
sPrivateKeyPassword, cryptPaddingPKCS1)
bufToEncrypt is Buffer = StringToUTF8("?????? Test")
bufPrivateKey is Buffer
bufPublicKey is Buffer
(bufPrivateKey, bufPublicKey) = EncryptGenerateRSAKey(1024)
bufEncrypted is Buffer = EncryptAsymmetric(bufToEncrypt, bufPublicKey)
bufSign is Buffer = CertificateSignString(bufEncrypted, bufPrivateKey, "", ...
certSignatureOnly + certSHA256)
IF CertificateCheckString(bufEncrypted, bufSign, bufPublicKey, "", "", ...
certSignatureOnly + certSHA256) THEN
bufReadable is Buffer = DecryptAsymmetric(bufEncrypted, bufPrivateKey)
Trace("Authentic message")
Trace(UTF8ToString(bufReadable))
ELSE
Trace("Unauthenticated message")
END
Syntax
<Result> = EncryptAsymmetric(<Content to encrypt> , <Public key file> [, <Password> [, <Padding>]])
<Result>: Character string or Buffer Result of encryption for the specified message. <Content to encrypt>: Buffer Buffer to encrypt. Warning: The size of the message to be encrypted must be less than the key size 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 or secret string Key file password (if required).
New in version 2025Secret strings: If you use the secret string vault, the type of secret string used for this parameter must be "Ansi or Unicode string". To learn more about secret strings and how to use the vault, see Secret string vault. <Padding>: Optional Integer constant Padding mode for encrypted data to be compatible with the size required by block encryption algorithms:
| | cryptPaddingOAEP | Padding according to the OAEP algorithm (Optimal Asymmetric Encryption Padding). | cryptPaddingPKCS1 (Default value) | Padding according to the PKCS 1 algorithm (Public Key Cryptographic Standards). |
Related Examples:
|
Unit examples (WINDEV): Asymmetric encryption
[ + ] Using the asymmetric encryption functions (EncryptAsymmetric, DecryptAsymmetric)
|
Business / UI classification: Business Logic
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|