php sha512解密,PHP加密函数 sha256 sha512 sha256_file() sha512_file()
发布日期:2021-06-24 10:12:02 浏览次数:4 分类:技术文章

本文共 1324 字,大约阅读时间需要 4 分钟。

/*

* 以下代码实现PHP sha256() sha256_file() sha512() sha512_file() PHP 5.1.2+完美兼容

* @param string $data 要计算散列值的字符串

* @param boolean $rawOutput 为true时返回原始二进制数据,否则返回字符串

* @param string file 要计算散列值的文件名,可以是单独的文件名,也可以包含路径,绝对路径相对路径都可以

* @return boolean | string 参数无效或者文件不存在或者文件不可读时返回false,计算成功则返回对应的散列值

* @notes 使用示例 sha256('mrdede.com') sha512('mrdede.com') sha256_file('index.php') sha512_file('index.php')

*/

/* PHP sha256() */

function sha256($data, $rawOutput=false){

if(!is_scalar($data)){

return false;

}

$data = (string)$data;

$rawOutput = !!$rawOutput;

return hash('sha256', $data, $rawOutput);

}

/* PHP sha256_file() */

function sha256_file($file, $rawOutput=false){

if(!is_scalar($file)){

return false;

}

$file = (string)$file;

if(!is_file($file) || !is_readable($file)){

return false;

}

$rawOutput = !!$rawOutput;

return hash_file('sha256', $file, $rawOutput);

}

/* PHP sha512() */

function sha512($data, $rawOutput=false){

if(!is_scalar($data)){

return false;

}

$data = (string)$data;

$rawOutput = !!$rawOutput;

return hash('sha512', $data, $rawOutput);

}

/* PHP sha512_file()*/

function sha512_file($file, $rawOutput=false){

if(!is_scalar($file)){

return false;

}

$file = (string)$file;

if(!is_file($file) || !is_readable($file)){

return false;

}

$rawOutput = !!$rawOutput;

return hash_file('sha512', $file, $rawOutput);

}

转载地址:https://blog.csdn.net/weixin_32042443/article/details/115155471 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:php将文件夹打包zip文件,PHP把文件夹打包成ZIP文件
下一篇:java exec封装_Java 执行系统命令工具类(commons-exec)

发表评论

最新留言

不错!
[***.144.177.141]2024年04月13日 15时03分58秒