简体   繁体   中英

Is there a way to set signature format for ECDSA to BER encoding in java?

I'm trying to sign a message with a private key. It works well, but the signature is encoded in DER encoding . What I want is to get the signature in BER encoding . Here is the method used to sign :

public static byte[] sign(String plainText, String privateKeyPath) throws 
Exception {
    PrivateKey privateKey = getPrivate(privateKeyPath);
    System.out.println(privateKey.getAlgorithm());
    Signature ecdsaSign = Signature.getInstance("SHA256withECDSA", "BC");
    ecdsaSign.initSign(privateKey);
    ecdsaSign.update(plainText.getBytes("UTF-8"));
    byte[] signature = ecdsaSign.sign();
    return signature;
}

I'm using BouncyCastle library

DER encoding is valid BER encoding

From X.690 summary in wikipedia

DER (Distinguished Encoding Rules) is a restricted variant of BER for producing unequivocal transfer syntax for data structures described by ASN.1. Like CER, DER encodings are valid BER encodings. DER is the same thing as BER with all but one sender's options removed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM