C # class library that comes with sha265 returns a byte [] array
The length of this array is 32, js is the sha265 64, each byte is to be directly converted into 2 hex string.
After encryption is C # 44 is due to the array would be base64 encoded string.
C # also directly converted into the corresponding byte to hex string and the js are the same.
Further, str converted into byte [] Encoding If different arrays, SHA different, are generally js utf8.
public
static
string
SHA256(
string
str)
{
//如果str有中文,不同Encoding的sha是不同的!!
byte
[] SHA256Data = Encoding.UTF8.GetBytes(str);
SHA256Managed Sha256 =
new
SHA256Managed();
byte
[]
by
= Sha256.ComputeHash(SHA256Data);
return
BitConverter.ToString(
by
).Replace(
"-"
,
""
).ToLower();
//64
//return Convert.ToBase64String(by); //44
}
static
void
Main(
string
[] args)
{
string
s =
"hello world"
;
//sha265=b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
string
sha = SHA256(s);
Console.WriteLine(
"{0}\n{1} \nLength: {2}"
,s, sha, sha.Length);
}
I personally use! I do not know if you can add Q: 961823316