rsaPublicKeyFromDERBytes static method
Decode the given bytes
into an RSAPublicKey
.
Implementation
static RSAPublicKey rsaPublicKeyFromDERBytes(Uint8List bytes) {
final ASN1Parser ans1Parser = ASN1Parser(bytes);
final ASN1Sequence topLevelSeq = ans1Parser.nextObject() as ASN1Sequence;
late final ASN1Sequence publicKeySeq;
if (topLevelSeq.elements![1].runtimeType == ASN1BitString) {
final ASN1BitString publicKeyBitString =
topLevelSeq.elements![1] as ASN1BitString;
final ASN1Parser publicKeyAsn =
ASN1Parser(publicKeyBitString.stringValues as Uint8List?);
publicKeySeq = publicKeyAsn.nextObject() as ASN1Sequence;
} else {
publicKeySeq = topLevelSeq;
}
final ASN1Integer modulus = publicKeySeq.elements![0] as ASN1Integer;
final ASN1Integer exponent = publicKeySeq.elements![1] as ASN1Integer;
final rsaPublickey = RSAPublicKey(modulus.integer!, exponent.integer!);
return rsaPublickey;
}