简体   繁体   English

将sha1转换为sha256

[英]Converting sha1 to sha256

I have a .sh file generating an openssl sha256 key 我有一个.sh文件生成openssl sha256密钥

$(echo -n ${DATA} | openssl sha256 -binary | base64)

And need to generate same key to compare it to using sha256 in my php file, the old one is sha1. 并且需要生成相同的密钥以将其与在我的php文件中使用sha256进行比较,而旧的是sha1。 This is my php code right now, which outputs fine sha1 string. 这是我现在的php代码,它输出良好的sha1字符串。

$params['Code'] = base64_encode(sha1($params['Product'] . $params['Model'] . $params['Number'],true));

I changed sha1 to sha256, and I get internal server error. 我将sha1更改为sha256,并且出现内部服务器错误。

It seems you want to use this: 看来您想使用这个:

$data = $params['Product'] . $params['Model'] . $params['Number'];
$params['Code'] = base64_encode(hash('sha256', $data, true));

but I also fail to understand why this is difficult to arrive at, given the first comment by Magnus Eriksson. 但是,根据马格努斯·埃里克森(Magnus Eriksson)的第一条评论,我也无法理解为什么很难做到这一点。

Note that we have no way to verify that this will result in the same output, as you expect. 请注意,我们无法验证这是否会产生与您期望的相同的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM