コード例 #1
0
        public byte[] Finish()
        {
            _digest.TransformFinalBlock(new byte[0], 0, 0);
            var hash = _digest.Hash;

            _digest.Dispose();
            return(hash);
        }
コード例 #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && _implementation != null)
     {
         _implementation.Dispose();
         _implementation = null;
     }
     base.Dispose(disposing);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: OMV0102/infbez3
        // функция для хэширования массива байт заданным алгоритмом, на выходе 16-ричная строка
        // аргументы: входные байты сообщения, алгоритм хэширования
        public static string HeshAlg(Byte[] arrayByte_in, string selectedAlgHesh)
        {
            byte[] arrayByte_out = new byte[0]; // Выходная последовательность байт после хеширования
            string heshString    = "";          // Хеш строка (16 ричный вид)

            try
            {
                switch (selectedAlgHesh) // Получение хеша определенным алгоритмом
                {
                case "MD5":
                    MD5 md5 = MD5.Create();
                    arrayByte_out = md5.ComputeHash(arrayByte_in);
                    md5.Dispose();
                    break;

                case "RIPEMD160":
                    RIPEMD160 ripemd160 = RIPEMD160.Create();
                    arrayByte_out = ripemd160.ComputeHash(arrayByte_in);
                    ripemd160.Dispose();
                    break;

                case "SHA1":
                    SHA1 sha1 = SHA1.Create();
                    arrayByte_out = sha1.ComputeHash(arrayByte_in);
                    sha1.Dispose();
                    break;

                case "SHA256":
                    SHA256 sha256 = SHA256.Create();
                    arrayByte_out = sha256.ComputeHash(arrayByte_in);
                    sha256.Dispose();
                    break;

                case "SHA384":
                    SHA384 sha384 = SHA384.Create();
                    arrayByte_out = sha384.ComputeHash(arrayByte_in);
                    sha384.Dispose();
                    break;

                case "SHA512":
                    SHA512 sha512 = SHA512.Create();
                    arrayByte_out = sha512.ComputeHash(arrayByte_in);
                    sha512.Dispose();
                    break;

                default: break;
                }
                heshString = BitConverter.ToString(arrayByte_out).Replace("-", "");
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message, "НЕПРЕДВИДЕННАЯ ОШИБКА", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(heshString);
        }
コード例 #4
0
        // The bulk of the clean-up code is implemented in Dispose(bool)
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // free managed resources

                _hashEncryptor.Dispose();
            }
            // free native resources here if there are any
        }
コード例 #5
0
        public static string GetSHA512(string input)
        {
            SHA512 sha512 = SHA512.Create();

            byte[] data = sha512.ComputeHash(Encoding.UTF8.GetBytes(input));

            sha512.Dispose();

            return(BytesToHash(data));
        }
コード例 #6
0
ファイル: Usuario.cs プロジェクト: Itzanh/ERPCraft
        public static bool verifyHash(string hash, string pwd, int iteraciones)
        {
            byte[] currentHash = Encoding.UTF8.GetBytes(pwd);
            SHA512 sha512      = SHA512.Create();

            for (int i = 0; i < iteraciones; i++)
            {
                currentHash = sha512.ComputeHash(currentHash);
            }
            sha512.Dispose();
            return(hashToHex(currentHash).Equals(hash));
        }
コード例 #7
0
ファイル: Usuario.cs プロジェクト: Itzanh/ERPCraft
        public static string hash(string data, int rounds = 5000)
        {
            byte[] hash = Encoding.UTF8.GetBytes(data);
            SHA512 sha  = SHA512.Create();

            for (int i = 0; i < rounds; i++)
            {
                hash = sha.ComputeHash(hash);
            }
            sha.Dispose();
            return(hashToHex(hash));
        }
コード例 #8
0
        public static StringBuilder encrypt(string password)
        {
            SHA512 sha = SHA512.Create();

            byte[]        hash = sha.ComputeHash(Encoding.UTF8.GetBytes(password));
            StringBuilder sb   = new StringBuilder();

            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("x2"));
            }
            sha.Dispose();
            return(sb);
        }
コード例 #9
0
        public static byte[] ComputeHash(string path, HashType htype)
        {
            FileStream fs = null;

            Byte[] hash = null;

            fs          = new FileStream(path, FileMode.Open, FileAccess.Read);
            fs.Position = 0;

            switch (htype)
            {
            case HashType.MD5:
                MD5 md5 = MD5.Create();
                hash = md5.ComputeHash(fs);
                md5.Dispose();
                break;

            case HashType.SHA1:
                SHA1 sha1 = SHA1.Create();
                hash = sha1.ComputeHash(fs);
                sha1.Dispose();
                break;

            case HashType.SHA256:
                SHA256 sha256 = SHA256.Create();
                hash = sha256.ComputeHash(fs);
                sha256.Dispose();
                break;

            case HashType.SHA384:
                SHA384 sha384 = SHA384.Create();
                hash = sha384.ComputeHash(fs);
                sha384.Dispose();
                break;

            case HashType.SHA512:
                SHA512 sha512 = SHA512.Create();
                hash = sha512.ComputeHash(fs);
                sha512.Dispose();
                break;

            default:
                fs.Close();
                throw new HashException("invalid hash algorithm");
            }

            fs.Close();
            return(hash);
        }
コード例 #10
0
        public static string EncryptClave(string txt)
        {
            txt += "smallchungus";
            SHA512 sha = SHA512.Create();

            byte[]        bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(txt));
            StringBuilder sb    = new StringBuilder();

            for (int i = 0; i < bytes.Length; i++)
            {
                sb.Append(bytes[i].ToString("x2"));
            }
            sha.Dispose();
            return(sb.ToString());
        }
コード例 #11
0
ファイル: Hash.cs プロジェクト: ITInsiders/ToPlay
        public static string GetHash(TypeHash type, string text, byte[] salt = null)
        {
            salt = salt ?? GenerateSalt();
            byte[] plain = ASCIIEncoding.UTF8.GetBytes(text);

            int lenghtPlant = plain.Length,
                lenghtSalt  = salt.Length,
                lenght      = lenghtPlant + lenghtSalt;

            byte[] bytes = new byte[lenght];
            for (int i = 0; i < lenght; ++i)
            {
                if (i < lenghtPlant)
                {
                    bytes[i] = plain[i];
                }
                else
                {
                    bytes[i] = salt[i - lenghtPlant];
                }
            }

            byte[] hash = null;
            switch (type)
            {
            case TypeHash.SHA256:
                SHA256 sha256 = SHA256Managed.Create();
                hash = sha256.ComputeHash(bytes);
                sha256.Dispose();
                break;

            case TypeHash.SHA384:
                SHA384 sha384 = SHA384Managed.Create();
                hash = sha384.ComputeHash(bytes);
                sha384.Dispose();
                break;

            case TypeHash.SHA512:
                SHA512 sha512 = SHA512Managed.Create();
                hash = sha512.ComputeHash(bytes);
                sha512.Dispose();
                break;
            }

            return(GetStringFromHash(hash));
        }
コード例 #12
0
        public static byte[] ComputeHash(string pw, int salt)
        {
            pw = salt + pw + salt + pw + salt;

            SHA512 sha = SHA512.Create();

            byte[] back = sha.ComputeHash(ASCIIEncoding.UTF8.GetBytes(pw));

            back = sha.ComputeHash(back);

            back = sha.ComputeHash(back);

            back = sha.ComputeHash(back);
            sha.Dispose();

            return(back);
        }
コード例 #13
0
        private string EncryptClave()
        {
            string clave = txtpassword.Password;

            clave += "smallchungus";
            SHA512 sha = SHA512.Create();

            byte[]        bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(clave));
            StringBuilder sb    = new StringBuilder();

            for (int i = 0; i < bytes.Length; i++)
            {
                sb.Append(bytes[i].ToString("x2"));
            }
            sha.Dispose();
            return(sb.ToString());
        }
コード例 #14
0
        private StringBuilder EncriptaClave()
        {
            string clave = txtPassword.Password;

            clave += "Big Chungus Reconoce Arreglos.";
            SHA512 sha = SHA512.Create();

            byte[]        bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(clave));
            StringBuilder sb    = new StringBuilder();

            for (int i = 0; i < bytes.Length; i++)
            {
                sb.Append(bytes[i].ToString("x2"));
            }
            lblEncriptado.Content = sb.ToString();
            sha.Dispose();
            return(sb);
        }
コード例 #15
0
        public static byte[] ComputeHash(Stream s, HashType htype)
        {
            Byte[] hash = null;

            switch (htype)
            {
            case HashType.MD5:
                MD5 md5 = MD5.Create();
                hash = md5.ComputeHash(s);
                md5.Dispose();
                break;

            case HashType.SHA1:
                SHA1 sha1 = SHA1.Create();
                hash = sha1.ComputeHash(s);
                sha1.Dispose();
                break;

            case HashType.SHA256:
                SHA256 sha256 = SHA256.Create();
                hash = sha256.ComputeHash(s);
                sha256.Dispose();
                break;

            case HashType.SHA384:
                SHA384 sha384 = SHA384.Create();
                hash = sha384.ComputeHash(s);
                sha384.Dispose();
                break;

            case HashType.SHA512:
                SHA512 sha512 = SHA512.Create();
                hash = sha512.ComputeHash(s);
                sha512.Dispose();
                break;

            default:
                throw new HashException("invalid hash algorithm");
            }

            return(hash);
        }
コード例 #16
0
        public static string ToSHA512(this string value)
        {
            //Khai báo chuỗi chứa kết quả
            StringBuilder stringBuilder = new StringBuilder();
            //Khai báo đối tượng hỗ trợ băm theo hàm SHA256
            SHA512 hash = SHA512.Create();
            //Khai báo bảng mã sẽ sử dụng
            Encoding encoding = Encoding.UTF8;

            //Chuyển giá trị đầu vào thành mảng byte
            byte[] inputBytes = encoding.GetBytes(value);
            //Băm mảng byte đầu vào
            Byte[] result = hash.ComputeHash(inputBytes);
            //Thu hồi đối tượng băm
            hash.Dispose();
            //Xử lý kết quả
            foreach (Byte Byte in result)
            {
                stringBuilder.Append(Byte.ToString("x2"));
            }
            //Trả về kết quả
            return(stringBuilder.ToString());
        }
コード例 #17
0
 public void Dispose()
 {
     _sha1.Dispose();
     _sha256.Dispose();
     _sha512.Dispose();
 }
コード例 #18
0
 public void Dispose()
 {
     _hashFunc.Dispose();
 }
コード例 #19
0
 public void Dispose()
 {
     _sha512.Clear();
     _sha512.Dispose();
 }
コード例 #20
0
 private void UManage_FormClosing(object sender, FormClosingEventArgs e)
 {
     sHA.Dispose();
     Dispose();
 }
コード例 #21
0
ファイル: SHA512Hasher.cs プロジェクト: redradist/MaYSharp
 public void Dispose()
 {
     hasher.Dispose();
 }
コード例 #22
0
 public void Dispose()
 {
     _hash.Dispose();
 }