好的,希望标题不会吓跑你。我使用Ruby创建sha1哈希,但它必须遵循我们的其他系统用来创建哈希的公式。通过.net技术在Ruby中创建SHA1哈希值
我该如何通过Ruby来做以下事情?我创建的哈希值很好 - 但格式化的东西让我感到困惑 - 好奇Ruby标准库中是否存在相同的东西。
System Security Cryptography (MSDN)
下面是我试图转换为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); }
上面的代码是否要模拟C#?您能否引用它作为代码并为我们这些没有C#的人添加最终输出? – 2013-03-21 21:35:29