[英]Convert RSA pem key String to der byte[]
I'm trying to convert an RSA pem key (contained in a String) to a byte[], like this method does when given a .pem file FileInputStream: 我正在尝试将RSA pem密钥(包含在字符串中)转换为byte [],就像在给定.pem文件FileInputStream时,此方法一样:
http://jets3t.s3.amazonaws.com/api/org/jets3t/service/security/EncryptionUtil.html#convertRsaPemToDer(java.io.InputStream) http://jets3t.s3.amazonaws.com/api/org/jets3t/service/security/EncryptionUtil.html#convertRsaPemToDer(java.io.InputStream)
I've tried this: 我已经试过了:
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());
I expect the result to be equivalent to what would be returned by org.jets3t.service.security.EncryptionUtil.convertRsaPemToDer()
but it does not seem to be working when generating a CloudFront streaming URL. 我希望结果与
org.jets3t.service.security.EncryptionUtil.convertRsaPemToDer()
返回的结果相同,但在生成CloudFront流URL时似乎无法正常工作。
Any idea what I'm doing wrong? 知道我在做什么错吗?
Just wrap the string in a ByteArrayInputStream
and you can use the method you linked: 只需将字符串包装在
ByteArrayInputStream
,就可以使用链接的方法:
InputStream pemStream = new ByteArrayInputStream(pemKey.getBytes());
byte[] derKey = EncryptionUtil.convertRsaPemToDer(pemStream);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.