在我的数据库中我有sql,
DECLARE @InputString nvarchar(15) ='pass' DECLARE @InputSalt nvarchar(36) = 'FC94C37C-03A3-49A3-9B9F-D4A82E708618' DECLARE @HashThis nvarchar(100) Declare @BinaryHash varbinary(max) set @HashThis = @InputString + @InputSalt set @BinaryHash= HASHBYTES('SHA1',@HashThis) SELECT CAST(N'' AS XML).value('xs:base64Binary(xs:hexBinary(sql:variable("@BinaryHash")))','VARCHAR(MAX)')
和C#我有,
public static string HashString(string cleartext) { byte[] clearBytes = System.Text.Encoding.UTF8.GetBytes(cleartext); return HashBytes(clearBytes); } public static string HashBytes(byte[] clearBytes) { var hasher = System.Security.Cryptography.SHA1.Create(); byte[] hashBytes = hasher.ComputeHash(clearBytes); string hash = System.Convert.ToBase64String(hashBytes); hasher.Clear(); return hash; } HashString("passFC94C37C-03A3-49A3-9B9F-D4A82E708618")
但哈希是不同的?
C# Output: S55Nz1lyGweoJEHWcC6zFxJDKWQ= sql Output: 4jqyC1pLJ0hW+AMNk8GOWCC99KY=