decodePkcs12Pure function

PurePkcs12Bundle decodePkcs12Pure(
  1. Uint8List bytes, {
  2. required String password,
  3. bool verifyMac = true,
})

Decodes a PKCS#12/PFX file in pure Dart.

verifyMac checks the file MAC before decrypting, which tells a wrong password apart from a corrupted file. Turn it off only for MAC-less files written by old tooling.

Implementation

PurePkcs12Bundle decodePkcs12Pure(
  Uint8List bytes, {
  required String password,
  bool verifyMac = true,
}) {
  // Any encoding defect becomes a PurePkcs12Exception: callers should not
  // have to tell a DER parser FormatException apart from anything else.
  try {
    return _decode(bytes, password, verifyMac);
  } on FormatException catch (e) {
    throw PurePkcs12Exception('Not a valid PKCS#12 file: ${e.message}');
  } on RangeError catch (e) {
    throw PurePkcs12Exception('Unexpected PKCS#12 structure: ${e.message}');
  } on TypeError {
    throw PurePkcs12Exception('Unexpected PKCS#12 structure');
  }
}