Language: C#
SHA256Encrypt static function
using System.Security.Cryptography; using System.Text; using System.Web; public static string SHA256Encrypt(string source, int digitRandom) { string outputHash = String.Empty; try { string hashResult = String.Empty; SHA256Managed sha = new SHA256Managed(); byte[] Data = Encoding.UTF8.GetBytes(source); byte[] Salt = new byte[digitRandom]; byte[] DataAndSalt = new byte[Data.Length + digitRandom]; Array.Copy(Data, DataAndSalt, Data.Length); Array.Copy(Salt, 0, DataAndSalt, Data.Length, digitRandom); byte[] HashOut = sha.ComputeHash(DataAndSalt); //remove bad character in Url transmission "+/=" hashResult = Convert.ToBase64String(HashOut); hashResult = hashResult.Replace("+", ""); hashResult = hashResult.Replace("/", ""); hashResult = hashResult.Replace("=", ""); // final result outputHash = hashResult; } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); return String.Empty; } return outputHash; }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

