Dart Requires Chilkat v11.0.0+
Dart
RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature
See more RSA Examples
Demonstrates how to RSA sign something using a private key loaded from a .pfx/.p12. The RSA signature is returned in Base64 encoded format.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final rsa = CkRsa();
// Load the .pfx/.p12
final pfx = CkPfx();
try {
pfx.loadPfxFile('qa_data/pfx/myKey.p12', 'myPassword');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Get the default private key.
final privKey = CkPrivateKey();
try {
pfx.privateKeyAt(0, privKey);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Import the private key into the RSA component:
try {
rsa.usePrivateKey(privKey);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Get the signature in base64
rsa.encodingMode = 'base64';
final strData = 'This is the string to be signed.';
// Sign the string using the sha256 hash algorithm.
// Other valid choices are "sha384", "sha512", "sha-1", "md2" and "md5".
final base64Sig = rsa.signStringENC(strData, 'sha256');
print(base64Sig);
print('Success!');
}