toASN1 method
Implementation
String toASN1({bool toPkcs1 = true, Iterable<ASN1Object>? parameters}) {
final dModP = d % (p - BigInt.from(1));
final dModQ = d % (q - BigInt.from(1));
final coefficient = q.modInverse(p);
final encoded = ASN1Sequence([
ASN1Integer.fromNum(0),
ASN1Integer(n),
ASN1Integer(e),
ASN1Integer(d),
ASN1Integer(p),
ASN1Integer(q),
ASN1Integer(dModP),
ASN1Integer(dModQ),
ASN1Integer(coefficient),
]).encode();
if (toPkcs1) {
return base64Encode(encoded);
}
return base64Encode(ASN1Sequence([
ASN1Integer.fromNum(0),
ASN1Sequence([
ASN1ObjectIdentifier.fromString('1.2.840.113549.1.1.1'),
...(parameters != null && parameters.isNotEmpty
? parameters
: [ASN1Null()]),
]),
ASN1OctetString(encoded)
]).encode());
}