public static string SHA512HashBlock(ref Blockchain block) { SHA512 hasher = SHA512Managed.Create(); var hash = hasher.ComputeHash(ObjectToByteHelper.ObjectToByteArray(Encoding.Default.GetBytes(block.Data + block.Index + block.PrevHash + block.TimeStamp + block.Nonce))); return(Convert.ToBase64String(hash)); }
public static string GetUniqueHash() { ManagementObjectSearcher MOS = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystemProduct"); ManagementObjectCollection moc = MOS.Get(); string s = ""; foreach (ManagementObject mo in moc) { s += mo["UUID"].ToString(); } MOS = new ManagementObjectSearcher("SELECT * FROM Win32_Processor"); moc = MOS.Get(); foreach (ManagementObject mo in moc) { s += mo["ProcessorId"].ToString(); } s += Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows_NT\\CurrentVersion", "ProductId", "FAIL"); byte[] ba = Encoding.UTF8.GetBytes(s); ba = SHA512Managed.Create().ComputeHash(ba); StringBuilder result = new StringBuilder(); for (int i = 0; i < ba.Length; i++) { result.Append(ba[i].ToString("X2")); } return(result.ToString()); }
internal static HashAlgorithm Create(HashingAlgorithm algoType) { HashAlgorithm hashingInstance = null; switch (algoType) { case HashingAlgorithm.MD5: hashingInstance = MD5.Create(); break; case HashingAlgorithm.SHA1: hashingInstance = SHA1Managed.Create(); break; case HashingAlgorithm.SHA256: hashingInstance = SHA256Managed.Create(); break; case HashingAlgorithm.SHA512: hashingInstance = SHA512Managed.Create(); break; default: throw new Exception("Incorrect use of HashingAlgorithm factory"); } return(hashingInstance); }
// // Calcul SHA512 // public static string SHA512HashFile(string Filename) { byte[] HashValue; string HashString = string.Empty; SHA512 MySHA512 = SHA512Managed.Create(); try { Stream MyStream = File.OpenRead(Filename); HashValue = MySHA512.ComputeHash(MyStream); StringBuilder output = new StringBuilder(2 + (HashValue.Length * 2)); foreach (byte b in HashValue) { output.Append(b.ToString("x2")); } HashString = output.ToString().ToUpper(); MyStream.Close(); return(HashString); } catch (Exception e5) { return(e5.Message); } }
public static byte[] get_SHA512_hash(string data_as_string) { byte[] data = Encoding.ASCII.GetBytes(data_as_string); SHA512 sha = SHA512Managed.Create(); return(sha.ComputeHash(data)); }
public void GenerateAndSetUniqueString() { SHA512 MySHA512 = SHA512Managed.Create(); GenerateRandomString(); String RandomAsciiString = GetRandomString(); Byte[] RandomAsciiStringByte; Byte[] RandomAsciiUniqueStringByte; Int16 Loop = 0; StringBuilder stringBuilder = new StringBuilder(); RandomAsciiStringByte = Encoding.ASCII.GetBytes(RandomAsciiString); RandomAsciiUniqueStringByte = MySHA512.ComputeHash(RandomAsciiStringByte); while (Loop < RandomAsciiUniqueStringByte.Length) { if (RandomAsciiUniqueStringByte[Loop] >= 48 && RandomAsciiUniqueStringByte[Loop] <= 57) { stringBuilder.Append((char)RandomAsciiUniqueStringByte[Loop]); } else if (RandomAsciiUniqueStringByte[Loop] >= 65 && RandomAsciiUniqueStringByte[Loop] <= 90) { stringBuilder.Append((char)RandomAsciiUniqueStringByte[Loop]); } else if (RandomAsciiUniqueStringByte[Loop] >= 97 && RandomAsciiUniqueStringByte[Loop] <= 122) { stringBuilder.Append((char)RandomAsciiUniqueStringByte[Loop]); } Loop += 1; } if (stringBuilder.ToString().CompareTo("") != 0) { SetUniqueString(stringBuilder.ToString()); } }
public static string SHA512(string input) { using (SHA512 hash = SHA512Managed.Create()) { return(string.Join("", hash.ComputeHash(Encoding.UTF8.GetBytes(input)).Select(item => item.ToString("x2")))); } }
public ReturnCode CreateAccount(params string[] authorizationParameters) { if (authorizationParameters.Length != 2) { return(ReturnCode.OperationInvalid); } UserMapper userMapper = new UserMapper(); User user = UserMapper.LoadByUserName(authorizationParameters[0]); if (null == user) { // Create the user var sha512 = SHA512Managed.Create(); // calculate a hash and check it against the password hash in the database var hashedpw = sha512.ComputeHash(Encoding.UTF8.GetBytes(authorizationParameters[1])); user = new User() { LoginName = authorizationParameters[0], PasswordHash = Convert.ToBase64String(hashedpw) }; userMapper.Save(user); return(ReturnCode.OK); } else { return(ReturnCode.InvalidUserPass); } }
private string HashSHA512(string data) { using (var sha512 = SHA512Managed.Create()) { return(ByteArrayToHex(sha512.ComputeHash(HexToByteArray(data)))); } }
public ReturnCode IsAuthorized(out User user, params string[] authorizationParameters) { user = null; if (authorizationParameters.Length != 2) { return(ReturnCode.OperationInvalid); } user = UserMapper.LoadByUserName(authorizationParameters[0]); if (null == user) { return(ReturnCode.InvalidUserPass); } // valid user, check password // create a hash object with SHA2-512 var sha512 = SHA512Managed.Create(); // calculate a hash and check it against the password hash in the database var hashedpw = sha512.ComputeHash(Encoding.UTF8.GetBytes(authorizationParameters[1])); if (user.PasswordHash.Equals(Convert.ToBase64String(hashedpw), StringComparison.OrdinalIgnoreCase)) { return(ReturnCode.OK); } else { return(ReturnCode.InvalidUserPass); } }
public void GetFileHashThrowsIfFileNameIsNull() { ArgumentNullException e = Assert.Throws <ArgumentNullException>(() => { Utils.GetFileHash(null, SHA512Managed.Create()); }); }
public static byte[] ToSha512HashBytes(this byte[] bytes) { using (var hash = SHA512Managed.Create()) { return(hash.ComputeHash(bytes)); } }
} // func PasswordCompare public static bool PasswordCompare(string testPassword, byte[] passwordHash) { if (passwordHash == null) { return(String.IsNullOrEmpty(testPassword)); } if (passwordHash.Length < 6) { throw new ArgumentException("invalid hash-length", nameof(passwordHash)); } if (BitConverter.ToInt16(passwordHash, 0) != 2) { throw new ArgumentException("invalid hash-version", nameof(passwordHash)); } var testPasswordBytes = Encoding.Unicode.GetBytes(testPassword); // create the SHA256 hash (Password + Salt) var sha = SHA512Managed.Create(); sha.TransformBlock(testPasswordBytes, 0, testPasswordBytes.Length, testPasswordBytes, 0); sha.TransformFinalBlock(passwordHash, 2, 4); return(Procs.CompareBytes(sha.Hash, 0, passwordHash, 6, sha.HashSize / 8)); } // func PasswordCompare
private static byte[] GetHash(SHA_Type shaType, byte[] bytes) { byte[] hash = null; switch (shaType) { case SHA_Type.SHA1: SHA1 sha1 = SHA1Managed.Create(); hash = sha1.ComputeHash(bytes); break; case SHA_Type.SHA256: SHA256 sha256 = SHA256Managed.Create(); hash = sha256.ComputeHash(bytes); break; case SHA_Type.SHA512: SHA512 sha512 = SHA512Managed.Create(); hash = sha512.ComputeHash(bytes); break; default: throw new NotSupportedException(); } return(hash); }
private static byte[] ComputeHash(byte[] m) { using (var sha512 = SHA512Managed.Create()) { return(sha512.ComputeHash(m)); } }
} // func HashPassword public unsafe static byte[] HashPassword(IntPtr passwordPtr, int length, int salt) { var c = (char *)passwordPtr.ToPointer(); // create hash function var sha = SHA512Managed.Create(); var b = new byte[2]; var i = 0; while (i < length) { unchecked { b[0] = (byte)(short)*c; b[1] = (byte)((short)*c >> 8); } sha.TransformBlock(b, 0, 2, b, 0); c++; i++; } b = BitConverter.GetBytes(salt); sha.TransformFinalBlock(b, 0, 4); // Erzeuge Salt+Hash var r = new byte[sha.HashSize / 8 + 6]; r[0] = 2; r[1] = 0; Array.Copy(b, 0, r, 2, 4); Array.Copy(sha.Hash, 0, r, 6, sha.HashSize / 8); return(r); } // func HashPassword
public static BigInteger GenerateSha512Hash(string inputString) { SHA512 sha512 = SHA512Managed.Create(); byte[] bytes = Encoding.UTF8.GetBytes(inputString); byte[] hash = sha512.ComputeHash(bytes); return(BigInteger.Abs(new BigInteger(hash))); }
//Generate SHA512 from file public static byte[] GenerateSHA512(byte[] input) { using (SHA512 sha512 = SHA512Managed.Create()) { byte[] hash = sha512.ComputeHash(input); return(hash); } }
public static string GeneratePassword(string pass) { SHA512 sha512 = SHA512Managed.Create(); byte[] bytes = Encoding.UTF8.GetBytes(pass); byte[] hash = sha512.ComputeHash(bytes); return(GetStringFromHash(hash)); }
public static string SHA512Hash(string input) { SHA512 sha512 = SHA512Managed.Create(); byte[] bytes = Encoding.UTF8.GetBytes(input); byte[] hash = sha512.ComputeHash(bytes); return(bytesToString(hash)); }
public static string EncryptPassword(string plainText) { SHA512 sha512 = SHA512Managed.Create(); byte[] bytes = Encoding.UTF8.GetBytes(plainText); byte[] hash = sha512.ComputeHash(bytes); return(GetStringFromHash(hash)); }
private static SHA512 GetHasher512() { if (_hasher512 == null) { _hasher512 = SHA512Managed.Create(); } return(_hasher512); }
public static string GenerateSHA512String(Stream stream) { using (var sha = SHA512Managed.Create()) { var hashValue = sha.ComputeHash(stream); return(GetStringFromHash(hashValue)); } }
public static TIdType GetSHA512 <TIdType>(byte[] buffer, int offset, int count) { Check <TIdType>(); SHA512 mySHA512 = SHA512Managed.Create(); var hashValue = mySHA512.ComputeHash(buffer, offset, count); return(GetHashAlgorithm <TIdType>(hashValue)); }
private static string GenerateSHA512Hash(string text) { SHA512 sha512 = SHA512Managed.Create(); byte[] bytes = Encoding.UTF8.GetBytes(text); byte[] hash = sha512.ComputeHash(bytes); return(GetStringFromHash(hash)); }
public static string get_SHA512_hash_as_string(string data_as_string) { byte[] data = Encoding.ASCII.GetBytes(data_as_string); SHA512 sha = SHA512Managed.Create(); var hash = sha.ComputeHash(data); return(Encoding.ASCII.GetString(hash));//tego nie wolno zmieniac bo psuje aes }
public static string GenerateSHA512String(string inputString) { SHA512 sha512 = SHA512Managed.Create(); byte[] bytes = Encoding.UTF8.GetBytes(inputString); byte[] hash = sha512.ComputeHash(bytes); return(GetStringFromHash(hash)); }
public string SHA512CalculationMethod(string filePath) { using (SHA512 SHA512 = SHA512Managed.Create()) { using (FileStream fileStream = File.OpenRead(filePath)) return(Convert.ToBase64String(SHA512.ComputeHash(fileStream))); } }
/// <summary> /// CheckSum512 method implementation /// </summary> public static byte[] CheckSum512(string value) { byte[] hash = null; using (SHA512 sha512 = SHA512Managed.Create()) { hash = sha512.ComputeHash(Encoding.UTF8.GetBytes(value)); } return(hash); }
static string createSHA512Hash(string value) { string result; using (var sha512 = SHA512Managed.Create()) result = Convert.ToBase64String(sha512.ComputeHash(Encoding.UTF8.GetBytes(value))); return(result); }