使用Base64.getEncoder()的字符串到公钥

时间:2018-04-23 08:38:16

标签: java string cryptography encode public-key-encryption

我从.PEM文件生成Java中的公钥,如下所示:

PublicKey pub = null;
        KeyFactory factory = KeyFactory.getInstance("RSA", "BC");
        try {
            /*PrivateKey priv = generatePrivateKey(factory, RESOURCES_DIR
                    + "id_rsa");*/

            pub = generatePublicKey(factory, RESOURCES_DIR
                    + "rsa_2048_pub.pem");

        } catch (InvalidKeySpecException e) {
            e.printStackTrace();
        }

然后我将其转换为字符串,如下所示:

String encodedPublicKey = Base64.getEncoder().encodeToString(pub.getEncoded());

现在我如何将其从字符串转换为公钥,以便再次将其作为 PublicKey 的类型?

0 个答案:

没有答案