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

RSA Sign using Base64 Private Key

See more RSA Examples

Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.

Chilkat Dart Downloads

Dart
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 privKey = CkPrivateKey();

  final sbPem = CkStringBuilder();
  sbPem.appendLine('-----BEGIN RSA PRIVATE KEY-----', true);
  sbPem.appendLine('MIIC .... j5A==', true);
  sbPem.appendLine('-----END RSA PRIVATE KEY-----', true);

  try {
    privKey.loadPem(sbPem.getAsString());
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final rsa = CkRsa();

  try {
    rsa.usePrivateKey(privKey);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final bd = CkBinData();
  bd.appendString('12345678', 'utf-8');

  try {
    rsa.signRawBd(bd);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Get the base64 RSA signature.
  print(bd.getEncoded('base64'));

  try {
    rsa.verifyRawBd(bd);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final strOriginal = bd.getString('utf-8');
  print(strOriginal);
}