Search in sources :

Example 1 with EcdsaP256Signature

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");
    }
}
Also used : EcdsaP256Signature(com.github.zhenwei.pkix.util.oer.its.EcdsaP256Signature) DERSequence(com.github.zhenwei.core.asn1.DERSequence) EcdsaP384Signature(com.github.zhenwei.pkix.util.oer.its.EcdsaP384Signature) ASN1Encodable(com.github.zhenwei.core.asn1.ASN1Encodable) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) IOException(java.io.IOException)

Aggregations

ASN1Encodable (com.github.zhenwei.core.asn1.ASN1Encodable)1 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)1 DERSequence (com.github.zhenwei.core.asn1.DERSequence)1 EcdsaP256Signature (com.github.zhenwei.pkix.util.oer.its.EcdsaP256Signature)1 EcdsaP384Signature (com.github.zhenwei.pkix.util.oer.its.EcdsaP384Signature)1 IOException (java.io.IOException)1