decodePKCS8PrivateKey static method
Plain PKCS8 private key format:
PrivateKeyInfo ::= SEQUENCE {
version Version,
privateKeyAlgorithm AlgorithmIdentifier {{PrivateKeyAlgorithms}},
privateKey PrivateKey,
attributes [0] Attributes OPTIONAL
}
Version ::= INTEGER {v1(0)} (v1,...)
PrivateKey ::= OCTET STRING
Implementation
static RSAPrivateKey decodePKCS8PrivateKey(Uint8List bytes) {
final parser = ASN1Parser(bytes);
if (!parser.hasNext()) {
throw ArgumentError('Not a ASN.1 sequence');
}
// Let's assume that is always a PKCS1 key
final seq = parser.nextObject() as ASN1Sequence;
final privateKey = seq.elements[2] as ASN1OctetString;
return decodePKCS1PrivateKey(privateKey.octets);
}