将 RSA 公钥从 XML 转换为 PEM (PHP) [英] Convert RSA public key, from XML to PEM (PHP)
问题描述
如何将 RSA 公钥从 XML 转换为 PEM (PHP)?
How convert RSA public key, from XML to PEM (PHP)?
推荐答案
我们知道
.pem -(隐私增强邮件)Base64编码的 DER 证书,随附在-----BEGIN CERTIFICATE-----"之间和-----结束证书-----"
.pem - (Privacy Enhanced Mail) Base64 encoded DER certificate, enclosed between "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----"
SignatureValue 元素包含Base64 编码的签名结果 -生成的签名中指定的参数SignatureMethod 元素 - 的应用后的 SignedInfo 元素指定的算法规范化方法.
The SignatureValue element contains the Base64 encoded signature result - the signature generated with the parameters specified in the SignatureMethod element - of the SignedInfo element after applying the algorithm specified by the CanonicalizationMethod.
所以我们结束了
$xml = simplexml_load_file($xmlFile); // or simplexml_load_string
$pem = "-----BEGIN CERTIFICATE-----\n";
$pem .= $xml->SignatureValue;
$pem .= "\n-----END CERTIFICATE-----";
// save to file
如果您的 xml 文件不是 XML_Signature
if your xml-file isn't a XML_Signature
$xml = simplexml_load_file($xmlFile); // or simplexml_load_string
$pem = "-----BEGIN CERTIFICATE-----\n";
$pem .= $xml->nodeWithWantedValue; // use base64_encode if needed
$pem .= "\n-----END CERTIFICATE-----";
这篇关于将 RSA 公钥从 XML 转换为 PEM (PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!