我正在尝试使用 ECDSA 和 spongycastle 验证一些签名内容。这是我用来生成具有brainpoolP512t1 ec曲线的密钥对的代码:
public static KeyPair getKeyPairbrainpoolP512t1() throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC", "SC"); ECNamedCurveParameterSpec curveParameterSpec = ECNamedCurveTable.getParameterSpec("brainpoolP512t1"); keyPairGenerator.initialize(curveParameterSpec, new SecureRandom()); return keyPairGenerator.generateKeyPair(); }
这是我用来签名和验证签名的代码:
private byte[] ecdsaSign(ECPrivateKey key, byte[] content) throws Exception {
Signature ecdsaSign = Signature.getInstance("SHA256withECDSA", "SC");
ecdsaSign.initSign(key);
ecdsaSign.update(content);
byte[] signature = ecdsaSign.sign();
return signature;
}
public static boolean ecdsaVerify(ECPublicKey key, byte[] content, byte[] signature) throws Exception {
Signature ecdsaVerify = Signature.getInstance("SHA256withECDSA", "SC");
ecdsaVerify.initVerify(key);
ecdsaVerify.update(content);
boolean result = ecdsaVerify.verify(signature);
return result;
}
我正在传递使用私钥和公钥签名的简单字符串消息的字节以进行验证。然而,我总是变得虚假。我究竟做错了什么?任何帮助都深表感谢。