1. 程式人生 > >java rsa加密報java.security.InvalidKeyException: IOException : algid parse error, not a sequence

java rsa加密報java.security.InvalidKeyException: IOException : algid parse error, not a sequence

java rsa 加密報這個異常,應該祕鑰的問題,: rsa 祕鑰不是pks8 格式

Caused by: java.security.InvalidKeyException: IOException : algid parse error, not a sequence

at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:351)
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:356)
at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:91)
at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:75)
at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:316)
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:213)

... 4 more

我的祕鑰是別人給的,用openssl生成的rsa金鑰對,openssl 會先生成一個.key檔案,然後根據這個來生成公鑰和私鑰,但是被一個不懂的人給坑了,一直給我的.key檔案的值,一直說是對的,如果你的java程式沒問題,但是卻一直報這個異常,很大的可能是祕鑰的問題