首頁 >後端開發 >php教程 >rsa - php openssl 函数不能用?

rsa - php openssl 函数不能用?

WBOY
WBOY原創
2016-06-06 20:15:561165瀏覽

<code>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));</code>

phpinfo();可看到openssl 扩展已安装
但是所有 openssl_* 函数都返回 false,

回复内容:

<code>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));</code>

phpinfo();可看到openssl 扩展已安装
但是所有 openssl_* 函数都返回 false,

用这个命令试试呢

<code>php -m|grep openssl</code>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn