Digital Signature Algorithm (ECDSA) Elliptic Curve on BouncyCastle

I am trying to implement ECDSA (Elliptic Curve Digital Signature Algorithm), but I could not find Java examples that use Bouncy Castle. I created the keys, but I really do not know what functions I should use to create the signature and verification.

public static KeyPair GenerateKeys() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("B-571"); KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC"); g.initialize(ecSpec, new SecureRandom()); return g.generateKeyPair(); } 
+7
java cryptography bouncycastle
source share
3 answers

owlstead is correct. And to develop a little more, you can do this:

 KeyPair pair = GenerateKeys(); Signature ecdsaSign = Signature.getInstance("SHA256withECDSA", "BC"); ecdsaSign.initSign(pair.getPrivate()); ecdsaSign.update(plaintext.getBytes("UTF-8")); byte[] signature = ecdsaSign.sign(); 

And to check:

 Signature ecdsaVerify = Signature.getInstance("SHA256withECDSA", "BC"); ecdsaVerify.initVerify(pair.getPublic()); ecdsaVerify.update(plaintext.getBytes("UTF-8")); boolean result = ecdsaVerify.verify(signature); 
+11
source share

BouncyCastle is a provider: a set of classes that provides some cryptographic functions that applications should use through the common API that Java works with. See Java Cryptography Architecture , especially the signature section, for how to create or verify a signature. Basically, you get an instance of java.security.Signature (with the static getInstance() method), then you initialize it with either a private key ( initSign() to generate a signature) or a public key ( initVerify() to verify the signature). Then you enter the message data with one or more calls to update() and finally call sign() or verify() to create or verify the signature.

+5
source share

You seem to use Bouncy Castle mainly as a provider. In this case, you can simply use Signature.getInstance("SHA256withECDSA", "BC") .

+1
source share

All Articles