我需要关于python中sha512编码的帮助。我正在尝试编写一段python代码,它应该与c代码保持一致
这里是C#中的方法
public string GenerateSHA512Hash(string data, sting salt) {
data = data.Replace(" ", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty).Replace("\r", string.Empty).Trim();
data = data + salt;
byte[] HashedBytes = Encoding.UTF8.GetBytes(data);
using(SHA512Managed hash = new SHA512Managed()) {
for (int j = 0; j < 2; j++) {
HashedBytes = hash.ComputeHash(HashedBytes);
var text = HashedBytes.ToBase16();
}
}
return HashedBytes.ToBase16();
}
我在python中获得了以下内容
import hashlib
def HashPAN(pan: str, salt: str):
data: str = pan + salt
data = data.replace(" ", "").replace("\n", "").replace("\t", "").replace("\r", "")
data_bytes = data.encode("utf-8")
hasher = hashlib.sha512()
# First Iteration
hasher.update(data_bytes)
hashed = hasher.digest()
h = hasher.hexdigest().upper()
# Second Iteration
hasher.update(hashed)
hashed = hasher.digest()
h = hasher.hexdigest().upper()
return hashed
在python中,标记为#First Iteration的部分的结果与C#代码(h=text)中循环中第一次的结果相匹配
但是,python中的第二次与c#中的第二次不匹配。有人能帮忙吗
我知道了如何在python中实现这一点
相关问题 更多 >
编程相关推荐