openssl_seal问题 [英] openssl_seal problems

查看:139
本文介绍了openssl_seal问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用PHP中的openssl_seal函数加载用于加密的公共密钥时遇到一些问题...

I'm having some problems loading in a public key for encrypting using openssl_seal function in PHP...

我创建了公开&使用openSSL命令行工具的私钥:

I've created the public & private keys using the openSSL command line tool:

openssl genrsa -des3 -out private.pem 1024

openssl rsa -in private.pem -out public.pem -outform PEM -pubout

但是,当我在PHP代码中运行它时,出现以下错误:

However, when I run it in my PHP code I get the following errors:

openssl_seal() [function.openssl-seal]: Don't know how to get public key from this private key
openssl_seal() [function.openssl-seal]: not a public key (1th member of pubkeys)

当我使用:openssl verify public.pem验证公钥时,我得到:

When I verify the public key using: openssl verify public.pem, I get:

unable to load certificate
1876:error:0906D06C:PEM routines:PEM_read_bio:no start line:.\crypto\pem\pem_lib
.c:648:Expecting: TRUSTED CERTIFICATE

有人知道为什么会这样吗?

Anyone know why this is happening?

PHP代码:

public function encrypt($valueToEncrypt, $publicKeyFile)
{
    $pk = file_get_contents($publicKeyFile);
    $publicKey = openssl_pkey_get_public($pk);

    $encrypted = '';
    $a_envelope = array();
    $a_key = array($publicKey);
    if (openssl_seal($valueToEncrypt, $encrypted, $a_envelope, $a_key) === FALSE)
            {
                while ($msg = openssl_error_string())
                    echo $msg . "<br />\n";
                die('Failed to encrypt data!');
            }
            openssl_free_key($publicKey);
....

推荐答案

对于遇到相同问题的任何人,此问题都与在Windows上安装xampp有关.在全新安装的php上的命令行上运行正常.

For anyone experiencing the same problem, the issue related to an install of xampp on windows. Running on the command line on a fresh install of just php worked fine.

这篇关于openssl_seal问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆