[英]OpenPGP (Bouncy Castle) with MSCAPI Keystore
我正在嘗試使用充氣城堡(v1.65)在 java 中進行加密/解密。 所以我需要將我的 MSCAPI(Windows-MY) 密鑰轉換為 PGP 密鑰。 當我嘗試使用 PSCK12 或 PSCK8 時,它就像一個魅力。 但是對於 MSCAPI(Windows-MY) Store,它不起作用。
這是我的代碼:
Security.addProvider(new BouncyCastleProvider());
JcaPGPKeyConverter converter = new JcaPGPKeyConverter().setProvider(TypeProvider.MSCAPI.getType());
PGPPublicKey pgpPublicKey = this.getPgpPublicKey(keyPair.getCertificate());
PGPPrivateKey pgpPrivateKey = converter.getPGPPrivateKey(pgpPublicKey, (PrivateKey)keyPair.getPrivateKey());
PGPKeyPair pgpKeyPair = new PGPKeyPair(pgpPublicKey, pgpPrivateKey);
ByteArrayOutputStream secretKeyOutput = new PGPCryptographieServiceImpl().pgpPrivateKeyFromKeyPair(pgpKeyPair);
File pgpKeyFile = new File(initialDirectory, nom.replace("*", "")
.replace("/", "").replace("<", "").replace(">", "").replace(":", "")
.replace("|", "").replace("\\", "").replace("?", "") + ".secret.asc");
FileUtils.writeByteArrayToFile(pgpKeyFile, secretKeyOutput.toByteArray());
}
使用 MSCAPI(Windows-MY) 密鑰,我遇到了這個異常:
sun.security.mscapi.CPrivateKey cannot be cast to java.security.interfaces.RSAPrivateCrtKey
有人可以幫我嗎?
我覺得回復太晚了。
您沒有鑄造正確的 object。
檢查 MSCAPI(Windows-MY) 商店支持的加密機制
一些提供商不允許您從他們的存儲庫中取出私鑰。 因此,請查看有關 MSCAPI(Windows-MY) Store 的 Microsoft 文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.