rsa - php openssl 函数不能用?
程序员文章站
2024-01-01 20:43:52
...
extension_loaded('openssl') or die('openssl扩展未安装');
$pukey='-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCivkFM06PJ2agLiF3rMyItmXbC
756SnYzJCPF2sBfUqxi8U/TFY72y5U4EdbgQMF+aP4ldBPUYpCXE7R6oQ96AEx/I
NCj9MDxGspXONXT4aPEkfNo7od0LzdLTLg+tdJklk7gti8jZg7kmuW3eG367KdEm
58Q116H+FI1D48kTNwIDAQAB
-----END PUBLIC KEY-----
';
$pikey='-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQCivkFM06PJ2agLiF3rMyItmXbC756SnYzJCPF2sBfUqxi8U/TF
Y72y5U4EdbgQMF+aP4ldBPUYpCXE7R6oQ96AEx/INCj9MDxGspXONXT4aPEkfNo7
od0LzdLTLg+tdJklk7gti8jZg7kmuW3eG367KdEm58Q116H+FI1D48kTNwIDAQAB
AoGBAJFLySMdRPr+n0CEpE1LnrUVcWmC45FEpiAKIwJzHyOZCgGB92OPtBqXDPuA
Wi/h8EjXdv0cYvJ4Atx5U0ipJ2jGrnBsxOx2pDj5TfrobNlaLlvK0N3Gqrb3l5kW
XUAJHe9kBReyNaenwkUPnMJ00QHReUUqtxCieM6trEicj9IxAkEAzgage1kFsDSs
tFxskHiADwKS4zoILMQ6LYY+1k7L+znRcU3k/a+/KiBzUIfOeDg2wcS60tknPqt0
cS8KWcvtWQJBAMo38psD8rTtg30mdSJpldlcuXQVUuDKnggseszeWKZaumE3H/pL
3XiT8zkl5UdNJ/N2AdeRRoPisxrJQ48bIw8CQFJy3nheaONaQR8wuZWbU4wuOIBM
sgbQRIQBbFYxVHpmagXQ6WoIkhUWxW8d2ifMP0WOKEHG+2ieDsxYyeijrokCQQCg
5ldhRIjvsTS4dcsp8H1NEFx3oyfouQ95TXsAW8KJyxMVmzkUfRzhfkc/J4oBa8Do
FPNuRKeo9M6x94aL7Xm9AkEApj3ixqfITd8gl1EO+mZb5rUgnW9nR37ExiQSMihO
pRQh1Igfmm90d+i7KYcTImwj5F5ofZS/Kvb737VRKLlJ6A==
-----END RSA PRIVATE KEY-----';
var_dump(openssl_pkey_get_private($pikey));
var_dump(openssl_pkey_get_public($pukey));
phpinfo();可看到openssl 扩展已安装
但是所有 openssl_* 函数都返回 false,
回复内容:
extension_loaded('openssl') or die('openssl扩展未安装');
$pukey='-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCivkFM06PJ2agLiF3rMyItmXbC
756SnYzJCPF2sBfUqxi8U/TFY72y5U4EdbgQMF+aP4ldBPUYpCXE7R6oQ96AEx/I
NCj9MDxGspXONXT4aPEkfNo7od0LzdLTLg+tdJklk7gti8jZg7kmuW3eG367KdEm
58Q116H+FI1D48kTNwIDAQAB
-----END PUBLIC KEY-----
';
$pikey='-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQCivkFM06PJ2agLiF3rMyItmXbC756SnYzJCPF2sBfUqxi8U/TF
Y72y5U4EdbgQMF+aP4ldBPUYpCXE7R6oQ96AEx/INCj9MDxGspXONXT4aPEkfNo7
od0LzdLTLg+tdJklk7gti8jZg7kmuW3eG367KdEm58Q116H+FI1D48kTNwIDAQAB
AoGBAJFLySMdRPr+n0CEpE1LnrUVcWmC45FEpiAKIwJzHyOZCgGB92OPtBqXDPuA
Wi/h8EjXdv0cYvJ4Atx5U0ipJ2jGrnBsxOx2pDj5TfrobNlaLlvK0N3Gqrb3l5kW
XUAJHe9kBReyNaenwkUPnMJ00QHReUUqtxCieM6trEicj9IxAkEAzgage1kFsDSs
tFxskHiADwKS4zoILMQ6LYY+1k7L+znRcU3k/a+/KiBzUIfOeDg2wcS60tknPqt0
cS8KWcvtWQJBAMo38psD8rTtg30mdSJpldlcuXQVUuDKnggseszeWKZaumE3H/pL
3XiT8zkl5UdNJ/N2AdeRRoPisxrJQ48bIw8CQFJy3nheaONaQR8wuZWbU4wuOIBM
sgbQRIQBbFYxVHpmagXQ6WoIkhUWxW8d2ifMP0WOKEHG+2ieDsxYyeijrokCQQCg
5ldhRIjvsTS4dcsp8H1NEFx3oyfouQ95TXsAW8KJyxMVmzkUfRzhfkc/J4oBa8Do
FPNuRKeo9M6x94aL7Xm9AkEApj3ixqfITd8gl1EO+mZb5rUgnW9nR37ExiQSMihO
pRQh1Igfmm90d+i7KYcTImwj5F5ofZS/Kvb737VRKLlJ6A==
-----END RSA PRIVATE KEY-----';
var_dump(openssl_pkey_get_private($pikey));
var_dump(openssl_pkey_get_public($pukey));
phpinfo();可看到openssl 扩展已安装
但是所有 openssl_* 函数都返回 false,
用这个命令试试呢
php -m|grep openssl
推荐阅读
-
rsa - php openssl 函数不能用?
-
urlencode php中可能用来加密字符串的函数[base64_encode、urlencode、sha1]
-
php获取网页标题和内容函数(不包含html标签)
-
php中可能用来加密字符串的函数[base64_encode、urlencode、sha1]
-
PHP stristr() 函数(不区分大小写的字符串查找)
-
php中使用exec,system等函数调用系统命令的方法(不建议使用,可导致安全问题)
-
PHP大小写问题:函数名和类名不区分,变量名区分
-
升级 PHP7.1 后 openssl 解密 mcrypt AES 数据不兼容问题的处理方法
-
php获取网页标题和内容函数(不包含html标签)
-
jQuery的$.get()函数不执行以及php端报错Uncaught Error: Call to a member function bind_param() on boolean in...