小工具知识网

当前位置: 首页 > 行业知识 > php 将rsa私钥 从DER格式的私钥转换为 PEM 格式

行业知识

php 将rsa私钥 从DER格式的私钥转换为 PEM 格式

2026-11-03 21:33:09 来源:互联网转载
$pemPrivateKey = '-----BEGIN PRIVATE KEY-----' . PHP_EOL    . chunk_split($key, 64, PHP_EOL)    . '-----END PRIVATE KEY-----' . PHP_EOL;
验证:dd(openssl_pkey_get_private($pemPrivateKey);

php/tags-41973.html" >���印结果为:OpenSSL key resource @128  (此字符串为rsa秘钥)

()

打印结果为:falese (代表此字符串不是rsa秘钥)

java语言rsa解码示例:

()

decoded为加密字符串   RSAPrivateKey为私钥

RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));Cipher cipher = Cipher.getInstance("RSA");cipher.init(Cipher.DECRYPT_MODE, priKey);outStr = new String(cipher.doFinal(inputByte));

PHP语言rsa解码示例:

$base为加密字符串 $pemPrivateKey为私钥  $decryptedData为解密结果openssl_private_decrypt($base, $decryptedData, $pemPrivateKey)

上一篇:个人服务器怎么做监控?

下一篇:怎么用ps美化人物?