好的,希望标题没有吓跑你。我正在使用 Ruby 创建一个 sha1 哈希,但它必须遵循我们其他系统用来创建哈希的公式。
如何通过 Ruby 执行以下操作?我很好地创建了哈希 - 但格式的东西让我感到困惑 - 好奇 Ruby 标准库中是否有等价的东西。
这是我试图转换为 Ruby 的 C# 代码。我的哈希值很好,但不确定 'String.Format("{0,2:X2}' 部分。
//create our SHA1 provider SHA1 sha = new SHA1CryptoServiceProvider(); String str = "Some value to hash"; String hashedValue; -- hashed value of the string //hash the data -- use ascii encoding byte[] hashedDataBytes = sha.ComputeHash(Encoding.ASCII.GetBytes(str)); //loop through each byte in the byte array foreach (byte b in hashedDataBytes) { //convert each byte -- append to result hashedValue += String.Format("{0,2:X2}", b); }