emsaPkcs1v15Encode function

List<int> emsaPkcs1v15Encode(
  1. List<int> msg,
  2. int outLength,
  3. EmsaHasher hasher
)

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
  ];
}