我正在尝试将十六进制ECDSA签名转换为ASN1 DER但收到错误。
请帮助指出正确的
Java函数:
public ASN1Sequence convertSignatureToASN1DER(String signatureHex)
{
System.out.println("Encoding hex signature to ASN1 DER... ");
System.out.println("Received signature string : "+signatureHex);
//extracting r and s
System.out.println("Extracting r and s as string");
byte[] first32SignatureBytes = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(signatureHex), 0,32);
String signaturePartR = Hex.encodeHexString(first32SignatureBytes);
byte[] last32SignatureBytes = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(signatureHex), 32,64);
String signaturePartS = Hex.encodeHexString(last32SignatureBytes);
//converting r and s to asn1 and putting them in sequence
System.out.println("Converting r and s to asn1 and putting them in sequence");
ASN1Integer r = new ASN1Integer(new BigInteger(signaturePartR, 16));
ASN1Integer s = new ASN1Integer(new BigInteger(signaturePartS, 16));
ASN1Sequence seq = new DERSequence(new ASN1Encodable[] { r, s });
System.out.println("r and s converted to asn1.. ");
return seq;
}
错误日志:
Received signature string : b2b31575f8536b284430C01217f688be3a9faf4ba0ba3a9093f983e40d630ec722a7a25b01403cff0d00b3b853d230f8e96ff832b15d4ccc75203cb65896a2d5
Extracting r and s as string
Converting r and s to asn1 and putting them in sequence
[2m2018-03-12 10:37:21.958[0;39m [31mERROR[0;39m [35m25020[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.a.c.c.C.[.[.[/].[dispatcherServlet] [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.VerifyError: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.(Ljava/lang/Object;)Z] with root cause
java.lang.VerifyError: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.(Ljava/lang/Object;)Z
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_77]
at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0_77]