toASN1 method

String toASN1({
  1. bool toPkcs1 = false,
  2. Iterable<ASN1Object>? parameters,
})

Implementation

String toASN1({bool toPkcs1 = false, Iterable<ASN1Object>? parameters}) {
  final encoded = ASN1Sequence([ASN1Integer(n), ASN1Integer(e)]).encode();
  if (toPkcs1) {
    return base64Encode(encoded);
  }
  return base64Encode(ASN1Sequence([
    ASN1Sequence([
      ASN1ObjectIdentifier.fromString('1.2.840.113549.1.1.1'),
      ...(parameters != null && parameters.isNotEmpty
          ? parameters
          : [ASN1Null()]),
    ]),
    ASN1BitString(encoded)
  ]).encode());
}