首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenPGP (Bouncy Castle)与

OpenPGP (Bouncy Castle)与
EN

Stack Overflow用户
提问于 2020-07-07 13:18:30
回答 1查看 80关注 0票数 0

我正在尝试用bouncy castle (v1.65)在java中进行加密/解密。因此,我需要将MSCAPI(Windows- my )密钥转换为PGP密钥。当我尝试使用PSCK12或PSCK8时,它就像是一种魔力。但对于MSCAPI(Windows-MY) Store,它不起作用。

下面是我的代码:

代码语言:javascript
复制
        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

有谁能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2021-03-06 18:46:40

我认为现在回复太晚了。

  1. 您没有转换正确的对象。

  1. 检查MSCAPI(Windows-MY) Store

支持的加密机制

  1. 某些提供商不允许您从其存储库中取出私钥。因此,请查看微软文档中有关MSCAPI(Windows-MY)存储的信息。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62768578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档