2

我正在尝试将 RSA pem 密钥(包含在字符串中)转换为字节 [],就像在给定 .pem 文件 FileInputStream 时此方法所做的那样:

http://jets3t.s3.amazonaws.com/api/org/jets3t/service/security/EncryptionUtil.html#convertRsaPemToDer(java.io.InputStream)

我试过这个:

String pemKey = "-----BEGIN RSA PRIVATE KEY-----\r\n"
         + "{base64 encoded key part omitted}\r\n"
         + "{base64 encoded key part omitted}\r\n"
         + "{base64 encoded key part omitted}\r\n"
         + "-----END RSA PRIVATE KEY-----";
String base64 = pemKey
        .replaceAll("\\s", "")
        .replace("-----BEGINRSAPRIVATEKEY-----", "")
        .replace("-----ENDRSAPRIVATEKEY-----", "");

return Base64.decode(base64.getBytes());

我希望结果与返回的结果相同,org.jets3t.service.security.EncryptionUtil.convertRsaPemToDer()但在生成 CloudFront 流 URL 时它似乎不起作用。

知道我做错了什么吗?

4

1 回答 1

3

只需将字符串包装在 a 中ByteArrayInputStream,您就可以使用链接的方法:

InputStream pemStream = new ByteArrayInputStream(pemKey.getBytes());
byte[] derKey = EncryptionUtil.convertRsaPemToDer(pemStream);
于 2014-01-16T22:12:12.333 回答