rsaPrivateKeyFromDERBytes static method

RSAPrivateKey rsaPrivateKeyFromDERBytes(
  1. Uint8List bytes
)

Decode the given bytes into an RSAPrivateKey.

Implementation

static RSAPrivateKey rsaPrivateKeyFromDERBytes(Uint8List bytes) {
  final ASN1Sequence topLevelSeq =
      ASN1Parser(bytes).nextObject() as ASN1Sequence;

  var privateKey = topLevelSeq.elements![2];

  final ASN1Parser asn1Parser = ASN1Parser(privateKey.valueBytes);

  final ASN1Sequence pkSeq = asn1Parser.nextObject() as ASN1Sequence;

  final ASN1Integer modulus = pkSeq.elements![1] as ASN1Integer;

  final ASN1Integer privateExponent = pkSeq.elements![3] as ASN1Integer;

  final ASN1Integer p = pkSeq.elements![4] as ASN1Integer;

  final ASN1Integer q = pkSeq.elements![5] as ASN1Integer;

  final RSAPrivateKey rsaPrivateKey = RSAPrivateKey(
      modulus.integer!, privateExponent.integer!, p.integer, q.integer);

  return rsaPrivateKey;
}