123456789101112131415161718192021222324252627282930313233343536373839404142 |
- /*===============================================================================
- Copyright (C) 2022 Immersal - Part of Hexagon. All Rights Reserved.
- This file is part of the Immersal SDK.
- The Immersal SDK cannot be copied, distributed, or made available to
- third-parties for commercial purposes without written permission of Immersal Ltd.
- Contact sdk@immersal.com for licensing requests.
- ===============================================================================*/
- using System;
- using System.Security.Cryptography;
- namespace Immersal.Samples.Util
- {
- public static class CryptoUtil
- {
- public static string MD5(byte[] bytes)
- {
- MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
- byte[] hashBytes = md5.ComputeHash(bytes);
- string hashString = "";
- for (int i = 0; i < hashBytes.Length; i++)
- hashString += Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
- return hashString.PadLeft(32, '0');
- }
- public static string SHA256(byte[] bytes)
- {
- SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
- byte[] hashBytes = sha256.ComputeHash(bytes);
- string hashString = "";
- for (int i = 0; i < hashBytes.Length; i++)
- hashString += Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
- return hashString.PadLeft(64, '0');
- }
- }
- }
|