[英]How to load file privakey file types is pem
我加載私有(private.pem)我的代碼是:
FileReader fileReader = new FileReader(new File(private.pem));
PEMReader r = new PEMReader(fileReader, new DefaultPasswordFinder("mypass".toCharArray()));
try {
KeyPair kp = (KeyPair) r.readObject();
} catch (IOException ex) {
throw new IOException("The private key could not be decrypted", ex);
} finally {
r.close();
fileReader.close();
}
錯誤是:引起原因:
java.io.IOException: problem creating RSA private key: java.security.NoSuchProviderException: No such provider: BC at org.bouncycastle.openssl.PEMReader.readObject(Unknown Source)
謝謝。
您是否嘗試添加:
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
編輯:您可能想要轉到為什么java.security.NoSuchProviderException沒有這樣的提供者:BC? 這可能導致相同的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.