0
私用密鑰生成問題在生成私鑰
public PrivateKey getStoredPrivateKey(String filePath) {
PrivateKey privateKey = null;
byte[] keydata = getKeyData(filePath);
PKCS8EncodedKeySpec encodedPrivateKey = new PKCS8EncodedKeySpec(keydata);
KeyFactory keyFactory = null;
try {
keyFactory = KeyFactory.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
System.out.println("hello");
privateKey = keyFactory.generatePrivate(encodedPrivateKey);
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
return privateKey;
}
我使用它在這裏
PrivateKey privateKey = new KryptoUtil().getStoredPrivateKey(privateKeyFilePath);
但其示值誤差
hello
java.security.spec.InvalidKeySpecException:
java.security.InvalidKeyException: IOException : version mismatch: (supported: 00, parsed: 03
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(Unknown Source)
我傳遞一個(或.p12)文件在getStoredPrivateKey(String filePath)函數中。
爲什麼它給錯誤?
你確定你的私鑰是spec PKCS#8的。嘗試使用其他規範,如RSAPrivateKeySpec –
如何識別其不是PKCS#8 – Mudit