我正在尝试使用充气城堡(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
有人可以帮我吗?