(Lianja) RSA Encrypt and OpenSSL Decrypt
Demonstrates how to use Chilkat to RSA encrypt, and then use OpenSSL to decrypt.
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loRsa = createobject("CkRsa")
llSuccess = loRsa.GenerateKey(2048)
loPrivKey = loRsa.ExportPrivateKeyObj()
llSuccess = loPrivKey.SavePkcs8PemFile("qa_output/privKey.pem")
release loPrivKey
loRsa.EncodingMode = "base64"
lcPlainText = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890"
llBUsePrivateKey = .F.
lcEncryptedStr = loRsa.EncryptStringENC(lcPlainText,llBUsePrivateKey)
loBd = createobject("CkBinData")
loBd.AppendEncoded(lcEncryptedStr,"base64")
llSuccess = loBd.WriteFile("qa_output/enc.dat")
// The OpenSSL command to decrypt is:
// openssl pkeyutl -in enc.dat -inkey privKey.pem -keyform PEM -pkeyopt rsa_padding_mode:pkcs1 -decrypt
? "OK"
release loRsa
release loBd
|