如何使用 java.security.Signature 进行验证
我已经有一对密钥,公共和私人的。我如何实际使用 java.security.Signature 来验证我用其中一个密钥签名的字符串?
编辑:
我有两个键作为字符串。 verify方法,其实是
verify(byte[] signature)
javadoc中说的:
verify(byte[]signature)
指示给定的签名是否可以 使用公钥或签名者的证书进行验证。
在调用验证方法之前,如何使该签名识别用于验证的公钥/私钥?换句话说,如何将字符串密钥转换为可以被签名接受的密钥对象?
I have a key pair already, public and private. How do I actually use the java.security.Signature
to do verification of a string I signed with one of the keys?
Edit:
I have both the keys as Strings. The verify method, it is actually
verify(byte[] signature)
The javadoc says:
verify(byte[] signature)
Indicates whether the given signature can be
verified using the public key or a certificate of the signer.
How would I make that signature recognize which public/private key to use for that verifying, before I call the verify method? In other words, how do I turn my string keys into key objects that would get accepted by signature?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
KeyFactory
将关键规范转换为对象。Signature.getInstance(algName)
获取签名实例。Signature
的initVerify
方法关联密钥以进行签名验证。update
来提供Signature
字节。verify
。从
KeyFactory
javadoc:KeyFactory
to translate key specifications to objects.Signature.getInstance(algName)
to get a signature instance.Signature
'sinitVerify
method to associate a key for signature verification.update
to feed theSignature
bytes.verify
.From the
KeyFactory
javadoc: