我有一个密钥库文件,我有一些加密文本。我必须使用存储在密钥库文件中的私钥来解密它。我无法弄清楚如何在我的java方法中提取该私钥。
public void decrypt(String encryptedText) {
byte[] decryptedData = null;
try {
FileInputStream is = new FileInputStream("/Users/rajat/workspace/dev/abc.jks");
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(is, "abc".toCharArray());
String alias = "xyz";
Key key = keystore.getKey(alias, "abc".toCharArray());
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, key);
decryptedData = cipher.doFinal(encryptedText.getBytes());
System.out.println("Decrypted Data: " + new String(decryptedData));
} catch (Exception e) {
e.printStackTrace();
}
}
当我跑步时,我得到错误:
javax.crypto.IllegalBlockSizeException: Data must not be longer than 256 bytes
at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:337)
at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)