rsaPublicKeyToFormattedPEM function

String rsaPublicKeyToFormattedPEM(
  1. RSAPublicKey publicKey
)

Export a RSAPublicKey as formatted PEM String which can be reversed using RSAPublicKey.fromPEM.

Implementation

String rsaPublicKeyToFormattedPEM(RSAPublicKey publicKey) {
  final base = rsaPublicKeyToString(publicKey);
  var formatted = '';
  for (var i = 0; i < base.length; i++) {
    if (i % 64 == 0 && i != 0) {
      formatted += '\n';
    }
    formatted += base[i];
  }
  return '-----BEGIN PUBLIC KEY-----\n$formatted\n-----END PUBLIC KEY-----';
}