gpt4 book ai didi

c# - SHA1 C# 等效于此 Java

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:12 26 4
gpt4 key购买 nike

在 C# 中寻找与此方法相同的等价物

try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(password.getBytes());
BigInteger hash = new BigInteger(1, md.digest());
hashword = hash.toString(16);
} catch (NoSuchAlgorithmException ex) {
}
}
return hashword;

最佳答案

在 C# 中 super 简单:

using System;
using System.Text;
using System.Security.Cryptography;

namespace CSharpSandbox
{
class Program
{
public static string HashPassword(string input)
{
var sha1 = SHA1Managed.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] outputBytes = sha1.ComputeHash(inputBytes);
return BitConverter.ToString(outputBytes).Replace("-", "").ToLower();
}

public static void Main(string[] args)
{
string output = HashPassword("The quick brown fox jumps over the lazy dog");
}
}
}

关于c# - SHA1 C# 等效于此 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4819794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com