pkcs12_parser 1.0.0
pkcs12_parser: ^1.0.0 copied to clipboard
Pure-Dart PKCS#12 (.pfx/.p12) parser. Extracts certificates, private and public keys without OpenSSL. Supports PBES1, PBES2 (AES), MAC verification, RSA and EC.
example/pkcs12_parser_example.dart
import 'dart:io';
import 'package:pkcs12_parser/pkcs12_parser.dart';
void main(List<String> args) {
if (args.isEmpty) {
print(
'Usage: dart run example/pkcs12_parser_example.dart <file.p12> [password]');
return;
}
final bytes = File(args[0]).readAsBytesSync();
final password = args.length > 1 ? args[1] : null;
final pfx = Pkcs12.load(bytes, password);
// Typed pointycastle keys — pattern-match for RSA vs EC.
switch (pfx.privateKey) {
case RSAPrivateKey key:
print('RSA key, ${key.modulus!.bitLength} bits');
case ECPrivateKey key:
print('EC key on ${key.parameters!.domainName}');
}
// PEM output.
print(pfx.privateKeyPem); // -----BEGIN PRIVATE KEY----- (PKCS#8)
print(pfx.certificatePem); // -----BEGIN CERTIFICATE-----
for (final ca in pfx.caChainPem) {
print(ca); // CA chain, issuer-ordered
}
}