【发布时间】:2020-04-17 03:27:53
【问题描述】:
我想用 SHA256withRSA/PSS 签名分两步,首先我散列一条消息,然后用 RSASSA-PSS 对摘要进行签名
byte[] document = {0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1};
MessageDigest digestor256 = MessageDigest.getInstance("SHA256", "BC");
byte[] documentDigest256 = digestor256.digest(document);
DigestAlgorithmIdentifierFinder hashAlgorithmFinder = new faultDigestAlgorithmIdentifierFinder();
AlgorithmIdentifier hashingAlgorithmIdentifier256 = hashAlgorithmFinder.find("SHA256");
DigestInfo digestInfo2 = new DigestInfo(hashingAlgorithmIdentifier256, documentDigest256);
Signature s2 = Signature.getInstance("NONEwithRSASSA-PSS", "BC");
MGF1ParameterSpec mgfParam = new MGF1ParameterSpec("SHA256");
PSSParameterSpec pssParam = new PSSParameterSpec("SHA256", "MGF1", mgfParam, 32, 1);
s.setParameter(pssParam);
s.initSign(keyPair.getPrivate());
s.update(digestInfo2.getEncoded());
byte[] signature = s.sign();
但我使用 SHA256withRSA/PSS 无法验证
Signature ver = Signature.getInstance("SHA256withRSA/PSS", "BC");
ver.setParameter(pssParam);
ver.initVerify(keyPair.getPublic());
ver.update(document);
boolean re = ver.verify(signature);
我需要一些帮助,谢谢你的帮助。
【问题讨论】: