ASN1PrivateKeyInfo.fromEccPem constructor

ASN1PrivateKeyInfo.fromEccPem(
  1. String pem
)

Creates an instance of PrivateKeyInfo for the given pem. The pem should represent a RSA private key in PKCS1.

Implementation

ASN1PrivateKeyInfo.fromEccPem(String pem) {
  var bytes = ASN1Utils.getBytesFromPEMString(pem);
  var private = ASN1Utils.ecPrivateKeyFromDerBytes(bytes);
  var asn1Parser = ASN1Parser(bytes);
  var privateKeySeq = asn1Parser.nextObject() as ASN1Sequence;
  var seq = ASN1Sequence(elements: [
    privateKeySeq.elements!.elementAt(0),
    privateKeySeq.elements!.elementAt(1),
    privateKeySeq.elements!.elementAt(3),
  ]);

  privateKey = ASN1OctetString(octets: seq.encode());

  version = ASN1Integer.fromtInt(0);
  var param = ASN1ObjectIdentifier.fromName(private.parameters!.domainName);
  privateKeyAlgorithm = ASN1AlgorithmIdentifier.fromName(
    'ecPublicKey',
    parameters: param,
  );
}