Dart Requires Chilkat v11.0.0+
Dart
RSA Encrypt and OpenSSL Decrypt
See more OpenSSL Examples
Demonstrates how to use Chilkat to RSA encrypt, and then use OpenSSL to decrypt.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final rsa = CkRsa();
final privKey = CkPrivateKey();
rsa.genKey(2048, privKey);
privKey.savePkcs8PemFile('qa_output/privKey.pem');
final pubKey = CkPublicKey();
privKey.toPublicKey(pubKey);
rsa.encodingMode = 'base64';
final plainText = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890';
final bUsePrivateKey = false;
rsa.usePublicKey(pubKey);
final encryptedStr = rsa.encryptStringENC(plainText, bUsePrivateKey);
final bd = CkBinData();
bd.appendEncoded(encryptedStr, 'base64');
bd.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
print('OK');
}