繁体   English   中英

Java SHA1withRSA验证始终为假,为什么?

[英]Java SHA1withRSA verification is always false, why?

我正在执行SHA1withRSA验证方法,但结果始终为false,是我编码错误还是公共密钥错误?

这是代码:

Signature signature = Signature.getInstance("SHA1withRSA");
File file = this.getPublicKey();
byte[] keyBytes = Files.readAllBytes(file.toPath());

// Setup RSA key
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
RSAPublicKey publicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);

// verify signatures
byte[] signatureBytes = Base64.decodeBase64(this.firmaB64);
signature.initVerify(publicKey);
signature.update(this.parteFirmada.getBytes());
boolean result = signature.verify(signatureBytes);

非常感谢!

我发现我正在验证的字符串不是签名的原始字符串,因此它是错误的。 验证码很好 ,以防有人感兴趣。

该字符串包含一个时间戳,并且要通过时间戳验证,它已被更改...该字符串永远无法通过验证!

感谢所有的评论

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM