openssl_private_encrypt()返回false,输出为0 [英] openssl_private_encrypt() returns false with output of 0

查看:1872
本文介绍了openssl_private_encrypt()返回false,输出为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP函数openssl_private_encrypt()来加密上传的文件,然后保存(见下面的代码片段),但是它的bool返回false,加密的内容返回没有返回。没有显示或报告错误。

  $ data = file_get_contents($ _ FILES ['files'] ['tmp_name'] [ 0]); 

openssl_private_encrypt($ data,$ encrypted,$ key);

$ hash = sha1($ encrypted);
file_put_contents('/ path / to / folder /'.$ hash,$ encrypted);有没有人有任何想法,为什么这不工作?

$ b $($)

谢谢

解决方案

我不确定PHP,但在C / C ++(OpenSSL)加密(RSA主要)对长度小于密钥大小的数据工作。通常它用于加密哈希值。如果要加密大量(更多〜256字节)数据量,最好使用一些对称(块)密码,如AES或TriDES。对称密码的速度要快得多。



PS对不起,我没有足够的声誉将这篇文章发表在评论中。


I am trying to use the PHP function openssl_private_encrypt() to encrypt an uploaded file prior to saving it (see code snippet below), however it's bool is returning false and the encrypted content return is returning nothing. No errors are being displayed or reported.

        $data = file_get_contents($_FILES['files']['tmp_name'][0]);

        openssl_private_encrypt($data,$encrypted,$key);

        $hash = sha1($encrypted);
        file_put_contents('/path/to/folder/'.$hash,$encrypted);

Does anyone have any ideas as to why this isn't working?

Thanks

解决方案

I'm not sure about PHP but in C/C++(OpenSSL) asymmetric encryption(RSA mainly) works on data with length less than the key size. And normally it is used to encrypt hash values. If you want to encrypt large(more the ~256 bytes)amount of data you'd better use some symmetric(block) cipher like AES or TriDES. Symmetric ciphers are much faster by the way.

PS Sorry I don't have enough reputation to put this post into comments.

这篇关于openssl_private_encrypt()返回false,输出为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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