在 BouncyCastle 上实施数字签名算法 (ECDSA) 的椭圆曲线

Elliptic Curve with Digital Signature Algorithm (ECDSA) implementation on BouncyCastle(在 BouncyCastle 上实施数字签名算法 (ECDSA) 的椭圆曲线)
本文介绍了在 BouncyCastle 上实施数字签名算法 (ECDSA) 的椭圆曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试实现 ECDSA(椭圆曲线数字签名算法),但我在 Java 中找不到任何使用 Bouncy Castle 的示例.我创建了密钥,但我真的不知道应该使用什么样的函数来创建签名并验证它.

I am trying to implement ECDSA (Elliptic Curve Digital Signature Algorithm) but I couldn't find any examples in Java which use Bouncy Castle. I created the keys, but I really don't know what kind of functions I should use to create a signature and verify it.

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();
}

推荐答案

owlstead 是正确的.更详细地说,你可以这样做:

owlstead is correct. And to elaborate a bit 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();

并验证:

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

这篇关于在 BouncyCastle 上实施数字签名算法 (ECDSA) 的椭圆曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)