Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final cert = CkCert();

  try {
    cert.loadFromFile('qa_data/pem/mf_public_rsa.pem');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final pubKey = CkPublicKey();
  cert.getPublicKey(pubKey);

  final rsa = CkRsa();
  rsa.usePublicKey(pubKey);

  rsa.encodingMode = 'base64';
  final encryptedStr = rsa.encryptStringENC('hello', false);
  print('encrypted string = $encryptedStr');
}