dpdfh60088 2012-05-02 21:54
浏览 94

openssl_seal问题

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

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

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)

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 Code:

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 />
";
                die('Failed to encrypt data!');
            }
            openssl_free_key($publicKey);
....
  • 写回答

2条回答 默认 最新

  • dongming6201 2012-05-15 12:26
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?