最近在處理一些事情,需要前端用到 SHA512 驗證東西,這時候我 Server 端也要驗證,所以就網路上找一下可以讓 Server 跟前端可以對起來的 SHA512 方法,因為試了一些
想說就記錄一下

Javascript 端:
主要是透過 https://github.com/emn178/js-sha512 這邊的 js lib 來做到
Source code :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="~/js/sha512.js"></script>
<span id="spanResult" style="color:red"></span>
<input id="inputString" type="text" placeholder="字串" value="許當麻麻麻" style="margin-top:20px" />
<button id="btnSHA512" type="button">SHA 512 JS</button>
<script>
$('#btnSHA512').click(function () {
$('#spanResult').html(sha512($('#inputString').val()));
});
</script>
C# Code :
var sha512CSP = new System.Security.Cryptography.SHA512CryptoServiceProvider();
ResultSHA512 = BitConverter.ToString(sha512CSP.ComputeHash(
System.Text.Encoding.UTF8.GetBytes(inputString2))).
Replace("-", string.Empty).ToLower();
這樣我對於字串 "許當麻麻麻" 做雜湊之後都是 "aa79f7b9e3ba67f495a740def4e2d883a83200f6448a1ab602c497152111c9dd4e4d734a93917d201af2d1be1d691792d12460bf7769dd3e19bbb4252b5add47"
紀錄一下怕之後要用到又要重新測試
reference :
https://github.com/emn178/js-sha512
https://dotblogs.com.tw/mrsunboss/2013/04/07/99955#SHA512
--
The bug existed in all possible states.
Until I ran the code.
如果這篇文章有幫助到您幫我分享一下,讓我有寫下去的動力...