RSA_verify返回零。有错误算法:不匹配

时间:2011-09-16 11:44:23

标签: java openssl cryptography rsa digital-signature

我使用Java IBMFIPS兼容签署消息 签署邮件的代码是:

//Signs the hash of each chunk and adds it to the Message Header
//data is 256Kb length  
//Get private key function is created by me to read the DER key formated file
GetPrivateKey privkey = new GetPrivateKey();   
Signature genSign = Signature.getInstance("SHA1withRSA","IBMJCEFIPS");
genSign.initSign(privkey.get());
genSign.update(data.getBytes());
byte[] byteSignedData = genSign.sign();

获取私钥功能代码

File privateKeyFile = new File("Certificates" + File.separator+"mykey.der");
byte[] encodedKey = new byte[(int)privateKeyFile.length()];
new FileInputStream(privateKeyFile).read(encodedKey);
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedKey);
KeyFactory kf = KeyFactory.getInstance("RSA","IBMJCEFIPS");
RSAPrivateCrtKey privatekey = (RSAPrivateCrtKey).generatePrivate(privateKeySpec);
return privatekey;

我正在使用openssl 0.9.8g,RSA_Verify()函数验证此签名。

我得到了错误:

  

RSA_verify_PKCS1因错误而失败   错误:04077064:rsa例程:RSA_verify:算法不匹配

0 个答案:

没有答案