use of com.github.zhenwei.pkix.util.oer.its.EcdsaP256Signature in project LinLong-Java by zhenwei1108.
the class ECDSAEncoder method toX962.
public static byte[] toX962(Signature signature) {
byte[] r;
byte[] s;
if (signature.getChoice() == Signature.ecdsaNistP256Signature || signature.getChoice() == Signature.ecdsaBrainpoolP256r1Signature) {
EcdsaP256Signature sig = EcdsaP256Signature.getInstance(signature.getValue());
r = ASN1OctetString.getInstance(sig.getrSig().getValue()).getOctets();
s = sig.getsSig().getOctets();
} else {
EcdsaP384Signature sig = EcdsaP384Signature.getInstance(signature.getValue());
r = ASN1OctetString.getInstance(sig.getrSig().getValue()).getOctets();
s = sig.getsSig().getOctets();
}
try {
return new DERSequence(new ASN1Encodable[] { new ASN1Integer(BigIntegers.fromUnsignedByteArray(r)), new ASN1Integer(BigIntegers.fromUnsignedByteArray(s)) }).getEncoded();
} catch (IOException ioException) {
throw new RuntimeException("der encoding r & s");
}
}
Aggregations