emsaPkcs1v15Encode function
Implements https://tools.ietf.org/html/rfc3447#section-9.2 specification.
Implementation
List<int> emsaPkcs1v15Encode(List<int> msg, int outLength, EmsaHasher hasher) {
final hashed = hasher.hash(msg);
final asn1 = ASN1Sequence([
ASN1Sequence([
ASN1Unknown(ASN1Type.objectIdentifierTag, hasher.asn1ObjectId),
ASN1Null()
]),
ASN1OctetString(Uint8List.fromList(hashed))
]);
final t = asn1.encode();
if (outLength < t.length + 11) {
throw Exception("intended encoded message length too short");
}
return <int>[
0,
1,
...List<int>.filled(outLength - t.length - 3, 255),
0,
...t
];
}