代码如下
public byte[] decrypt(RSAPrivateKey privateKey, String cipherText) throws Exception{
log.info("----------- 开始解密");
if (privateKey== null){
throw new Exception("解密私钥为空, 请设置");
}
log.info("----------- 创建cipher");
Cipher cipher= null;
try {
cipher= Cipher.getInstance("RSA", new BouncyCastleProvider());
log.info("----------- 创建cipher成功");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
log.info("----------- cipher初始化");
byte[] cache=Base64.decodeBase64(cipherText);
log.info("----------- 创建byte成功");
int inputLen = cache.length;
int offSet = 0;
StringBuffer str=new StringBuffer();
int i = 0;
log.info("----------- 对数据分段解密");
// 对数据分段解密
while (inputLen - offSet > 0)
{ log.info("----------- while1");
if ( inputLen - offSet > MAX_DECRYPT_BLOCK)
{log.info("----------- 解密1");
str.append(new String(cipher.doFinal(Base64.decodeBase64(cipherText), offSet, MAX_DECRYPT_BLOCK), encoding));
}
else
{log.info("----------- 解密2");
str.append(new String(cipher.doFinal(Base64.decodeBase64(cipherText), offSet, inputLen - offSet), encoding));
}
i++;
offSet = i * MAX_DECRYPT_BLOCK;
log.info("----------- while2");
}
log.info("-----------解密结束");
return str.toString().getBytes(encoding);
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此解密算法");
} catch (NoSuchPaddingException e) {
e.printStackTrace();
return null;
}catch (InvalidKeyException e) {
throw new Exception("解密私钥非法,请检查");
} catch (IllegalBlockSizeException e) {
throw new Exception("密文长度非法");
} catch (BadPaddingException e) {
throw new Exception("密文数据已损坏");
}
}
在本地windows环境jdk1.6下程序正常运行,但到Linux环境1.6jdk时日志显示到“----------- 创建cipher”就不往下走了,有知道怎么解决的吗?
坐等中。。。。。