rsaPublicKeyFromString function

RSAPublicKey rsaPublicKeyFromString(
  1. String publicKeyString
)

Create an RSAPublicKey from the given String.

Implementation

RSAPublicKey rsaPublicKeyFromString(String publicKeyString) {
  List<int> publicKeyDER = base64Decode(publicKeyString);
  final asn1Parser = ASN1Parser(publicKeyDER as Uint8List);
  final topLevelSeq = asn1Parser.nextObject() as ASN1Sequence;
  final publicKeyBitString = topLevelSeq.elements[1];

  final publicKeyAsn = ASN1Parser(publicKeyBitString.contentBytes());
  final publicKeySeq = publicKeyAsn.nextObject() as ASN1Sequence;
  final modulus = publicKeySeq.elements[0] as ASN1Integer;
  final exponent = publicKeySeq.elements[1] as ASN1Integer;

  return RSAPublicKey(modulus.valueAsBigInteger, exponent.valueAsBigInteger);
}