简体   繁体   English

将C#sha256转换为PHP

[英]C# sha256 into PHP

I've got a table of hashes and salts previously created by by another company. 我有一张以前由另一家公司创建的哈希表和盐表。 The hash was done in C# and the hash method is sha256. 哈希是在C#中完成的,哈希方法是sha256。 The logic behind this is sha256(password+salt) . 其背后的逻辑是sha256(password+salt)

An example of inputs: 输入示例:

password = 'rosnicka'
salt     = 'zxwqTy+XjaY=' 
hash     = '3jdt1+JL3MPmjYr2OoXdoUwNfuweuDCZa8/3g7SfsNg='

When I tried to run a hashing function in PHP 当我尝试在PHP中运行哈希函数时

the output of this is "1125ed47a7aa11bc1c54c841b5eb7a6e72aa8ad27e010e6e25baa5b2a86cffb3" 其输出为"1125ed47a7aa11bc1c54c841b5eb7a6e72aa8ad27e010e6e25baa5b2a86cffb3"

I get the same results using only hashing calculators 我仅使用哈希计算器得到相同的结果

I contacted them to find out what I'm doing wrong. 我与他们联系,以了解我在做什么错。 They told me, that are storing ASCII version of the hash in the database. 他们告诉我,这是在数据库中存储哈希的ASCII版本。 What should I do in order to get the same hash in PHP or what to do in order to convert their hash to the original sha256 hash? 我应该怎么做才能在PHP中获得相同的哈希值,或者怎么做才能将其哈希值转换为原始的sha256哈希值?

thanks a lot! 非常感谢!

As alex K said: 正如Alex K所说:

base64_encode(hash('sha256', 'rosnicka'.base64_decode('zxwqTy+XjaY='), true));

will do the trick 会成功的

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

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