{"action":"closed","issue":{"url":"https://api.github.com/repos/Caligatio/jsSHA/issues/23","labels_url":"https://api.github.com/repos/Caligatio/jsSHA/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/Caligatio/jsSHA/issues/23/comments","events_url":"https://api.github.com/repos/Caligatio/jsSHA/issues/23/events","html_url":"https://github.com/Caligatio/jsSHA/issues/23","id":54567276,"number":23,"title":"Hashing is different from C#","user":{"login":"iamdriz","id":801252,"avatar_url":"https://avatars.githubusercontent.com/u/801252?v=3","gravatar_id":"","url":"https://api.github.com/users/iamdriz","html_url":"https://github.com/iamdriz","followers_url":"https://api.github.com/users/iamdriz/followers","following_url":"https://api.github.com/users/iamdriz/following{/other_user}","gists_url":"https://api.github.com/users/iamdriz/gists{/gist_id}","starred_url":"https://api.github.com/users/iamdriz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamdriz/subscriptions","organizations_url":"https://api.github.com/users/iamdriz/orgs","repos_url":"https://api.github.com/users/iamdriz/repos","events_url":"https://api.github.com/users/iamdriz/events{/privacy}","received_events_url":"https://api.github.com/users/iamdriz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-01-16T11:48:08Z","updated_at":"2015-03-08T18:08:14Z","closed_at":"2015-03-08T18:08:14Z","body":"In C# I have the following code which hashes a string:\r\n\r\n~~~\r\nprivate static string Hash(string text)\r\n{\r\n    byte[] bytes = Encoding.Unicode.GetBytes(text);\r\n\r\n    using (var generator = new SHA256Managed())\r\n    {\r\n        byte[] hash = generator.ComputeHash(bytes);\r\n        return BytesToHex(hash);\r\n    }\r\n}\r\n\r\nprivate static string BytesToHex(byte[] bytes)\r\n{\r\n    var hex = new StringBuilder(bytes.Length * 2);\r\n    foreach (byte b in bytes)\r\n    {\r\n        hex.AppendFormat(\"{0:x2}\", b);\r\n    }\r\n\r\n    return hex.ToString();\r\n}\r\n\r\nreturn Hash(text);\r\n~~~\r\n\r\nThis encodes it with UTF-16 and because NodeJS Cryto does not support UTF-16 the following does not work:\r\n~~~\r\nreturn crypto.createHash('sha256').update(text).digest('hex');\r\n~~~\r\n\r\nI have tried this lib as it supports UTF-16 with:\r\n~~~\r\nvar shaObj = new jsSHA(text, \"TEXT\", \"UTF16\");\r\n\r\nreturn shaObj.getHash(\"SHA-256\", \"HEX\");\r\n~~~\r\n\r\nBut again I get a different hash to my C# version! Any ideas why?\r\n\r\n**In the end this works: `return crypto.createHash('sha256').update(text, 'ucs2').digest('hex');` but why does you library return a different hash?**"}}