Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
SHA Tester 2.0
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Text; using System.Security.Cryptography; using System.Globalization; namespace Rextester { public class Program { public static void Main(string[] args) { var user = "marcor"; var userId = "9585ac17-4b86-4b1e-963c-4100c736b432"; var DateUserCreated = "2017-01-11 17:35:20"; //Your code goes here Console.WriteLine("Client sends: " + Sha256StringHash(user)); Console.WriteLine("Server stores: " + Sha256StringHash(Sha256StringHash(user), GetSalt(Guid.Parse(userId), DateTime.Parse(DateUserCreated)))); } public static string Sha256StringHash(string input) { using (var shaM = new SHA256Managed()) { var hash = shaM.ComputeHash(Encoding.UTF8.GetBytes(input)); return HashToString(hash); } } public static string Sha256StringHash(string input, string salt) { using (var shaM = new SHA256Managed()) { var bytesInput = Encoding.UTF8.GetBytes(input); var bytesSalt = Encoding.UTF8.GetBytes(salt); var data = new byte[bytesInput.Length + bytesSalt.Length]; bytesInput.CopyTo(data, 0); bytesSalt.CopyTo(data, bytesInput.Length); var hash = shaM.ComputeHash(Encoding.UTF8.GetBytes(input)); return HashToString(hash); } } public static string GetSalt(Guid id, DateTime createdAt) { var toHash = createdAt.Day % 2 == 0 ? id.ToString() + createdAt : createdAt.ToString(CultureInfo.InvariantCulture) + id; using (var shaM = new SHA256Managed()) { var hash = shaM.ComputeHash(Encoding.UTF8.GetBytes(toHash)); return HashToString(hash).Substring(0, 5); } } private static string HashToString(byte[] hash) { var sBuilder = new StringBuilder(); foreach (var b in hash) sBuilder.Append(b.ToString("x2")); return sBuilder.ToString(); } } }
run
|
edit
|
history
|
help
0
LinqGroupContiguous
newstring vs regex
My C# (2)
jjj2
fuck this
UnityCubo
z
hacker
Builder Design Pattern
string formater placehoder