0
如何將私有DSA密鑰(4096位)的DER文件讀入AsymmetricKeyParameter以在DSASigner中使用?如何在彈性城堡(Java)中將DER DSA私鑰讀取爲AsymmetricKeyParameter
下面的代碼我想:
byte[] privateKeyBytes = FileUtils.readFileToByteArray(new File(
"sign-key-private.der"));
AsymmetricKeyParameter privateKey = PrivateKeyFactory
.createKey(privateKeyBytes);
結果是一個例外:
java.lang.IllegalArgumentException: unknown object in getInstance: org.bouncycastle.asn1.ASN1Integer
at org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source)
at org.bouncycastle.asn1.x509.AlgorithmIdentifier.getInstance(Unknown Source)
at org.bouncycastle.asn1.pkcs.PrivateKeyInfo.<init>(Unknown Source)
at org.bouncycastle.asn1.pkcs.PrivateKeyInfo.getInstance(Unknown Source)
at org.bouncycastle.crypto.util.PrivateKeyFactory.createKey(Unknown Source)
at test.security.core.Program.main(Program.java:41)
是以任何方式編碼的DER文件,或用密碼保護? – EpicPandaForce 2015-02-09 14:49:19
根據源,調用以下方法:'PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(new ASN1InputStream(inputStream).readObject()));'請嘗試手動執行此操作,並查看使用'new FileInputStream哪個步驟失敗「sign-key-private.der」);' – EpicPandaForce 2015-02-09 14:51:06
從源文件和堆棧跟蹤中,它試圖解析ANS編碼的算法標識符,期望一個序列,並得到一個ASN編碼的整數。那麼......你有可能使用openssl來轉儲.DER文件的內容,並確保它可以成功執行。 – Greycon 2015-02-09 17:25:56