如何使用私钥对字符串进行签名
如果我已经拥有 byte[]
或 String
形式的私钥,如何使用 SHA1withRSA
获取字符串签名?
How can I get the signature of a string using SHA1withRSA
if I already have the Private Key as byte[]
or String
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我想你所说的是你事先知道密钥对并且想用它来签名/验证。
请看下面的代码。
在这里,您需要更改方法 getKeyPair() 以提供您已知的密钥对。您可以从 java 密钥存储 [JKS] 加载它。
您不能只将任意字节数组作为您的公钥或私钥。它们应该是相关生成的。
I guess what you say is you know the key pair before hand and want to sign/verify with that.
Please see the following code.
Here you need to change the method getKeyPair() to supply your known key pair. You may load it from a java key store [JKS].
You can't just have an arbitrary byte array either as your public key or private key. They should be generated in relation.
我使用 bouncy-castle 对数据进行签名并验证。
你应该添加maven依赖:
将 RSA 私钥或公钥从磁盘文件加载到 Java 对象中
首先,我们需要能够将 RSA 私钥或公钥从磁盘文件加载到 Java 对象中Bouncy Castle 的适当类
创建 RSA 数字签名
验证 RSA 数字签名
I use bouncy-castle to sign data and verify it.
you should add maven dependency:
Load RSA private or public key from a disk file into a Java object
First, we need to be able to load RSA private or public key from a disk file into a Java object of a proper class from Bouncy Castle
Creation of an RSA digital signature
Verification of an RSA digital signature
您首先必须从字节数组创建一个公钥
,然后使用公钥进行加密。
现在只有拥有私钥的人才能读取您的数据
@rczajka:公钥是密钥。您可以使用它来签署只有所有者(拥有私钥)才能读取的内容。
You first must create a public key from array of bytes
and after using the publicKey to encrypt
Now only who have the privateKey can read your data
@rczajka: a publicKey is a key. You can use it to sign somethig that only the owner (that have the privateKey) can read.