本文介绍了从两个大整数创建ASN.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用HSM的Java程序,该程序与本机API一起为我提供ECDSA签名的R值和S值,这只是两个Big Integer。我需要使用这些Integer并创建ASN.1编码。关于我该怎么做的任何想法?我确实可以运行BouncyCastle,但是我不熟悉可用的选项。

I have a java program using an HSM that with the native API gives me and R and S value of an ECDSA signature which is just the two Big Integers. I need to take those Integers and create ASN.1 encoding. Any idea on how I could do that? I do have BouncyCastle up and running but, I am not familiar with the options available to me.

推荐答案

一个小例子来说明:

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

这篇关于从两个大整数创建ASN.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 00:49