简体   繁体   中英

Signing a message with privateKey (elliptic p256)

How do we sign a message with a givenPrivateKey in java with elliptic curve(p256)

Basically a java implementation of

let elliptic = new EC('p256')
const sig = elliptic.sign(msgHashHex, privateKey, null)

I dont want to generate new private/public key pair. My privateKey = 'abc'

Also please let me know if there is an online tool to play around with digital signatures.

Thanks a lot in advance.

PrivateKey privateKey = ; // your  EC p256 private key
byte[] msgHashHex = ; // byte array data

Signature signature = Signature.getInstance("ECDSA"); // or SHA256WithECDSA etc.
signature.initSign(privateKey);
signature.update(msgHashHex);   
byte[] result = signature.sign();

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