Create ASN.1 from two large integers

I have a java program using HSM that, using the API API, gives me both the R and S value of the ECDSA signature, which is just two large integers. I need to take these integers and create ASN.1 encoding. Any idea on how I can do this? I have a BouncyCastle and it works, but I am not familiar with the options available to me.

0
source share
1 answer

A small example to illustrate:

import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequence;

import javax.xml.bind.DatatypeConverter;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) throws Exception {
        BigInteger r = new BigInteger("29128391823901823918293108120938102381912839182390182391829310812093810238199");
        BigInteger s = new BigInteger("38663726871681756650018917824777578348866372687168175665001891782477757834811");

        ASN1Integer asn1R = new ASN1Integer(r);
        ASN1Integer asn1S = new ASN1Integer(s);

        DERSequence seq = new DERSequence(new ASN1Integer[]{asn1R, asn1S});
        byte[] encoded = seq.getEncoded();
        System.out.println(DatatypeConverter.printHexBinary(encoded));
    }
}
+3
source

Source: https://habr.com/ru/post/1693641/


All Articles