Пример #1
0
        /// <summary>
        /// Obtém a "Hash" de um texto (input) com base no algorítimo informado
        /// </summary>
        /// <param name="hashStringType">Tipo de Algorítimo de hash</param>
        /// <returns>Retorna string criptografada</returns>
        public string GetHashString(HashStringType hashStringType)
        {
            HashAlgorithm hashAlgorithm = null;

            string output;

            switch (hashStringType)
            {
            case HashStringType.MD5:
                hashAlgorithm = MD5.Create();
                break;

            case HashStringType.SHA1:
                hashAlgorithm = SHA1.Create();
                break;

            case HashStringType.SHA256:
                hashAlgorithm = SHA256.Create();
                break;

            case HashStringType.SHA384:
                hashAlgorithm = SHA384.Create();
                break;

            case HashStringType.SHA512:
                hashAlgorithm = SHA512.Create();
                break;

            default:
                break;
            }

            output = CommonHashString(hashAlgorithm, input);
            return(output);
        }
Пример #2
0
        /// <summary>
        /// <para>Obtém o resultado da aplicação do salt em Base64 Reduzido</para>
        /// </summary>
        /// <param name="hashType">Padrão de criptografia utilizada</param>
        /// <param name="iterations">Número de vezes que a iteração utiliza a chave</param>
        /// <param name="keySize">Tamanho da chave</param>
        /// <returns>Retorna a aplicação do salt em Base64 Reduzido</returns>
        public string Get(HashStringType hashType = HashStringType.SHA1, int iterations = 10, int keySize = 64)
        {
            byte[] bSalt    = Encoding.Default.GetBytes(salt);
            byte[] bInput   = Encoding.Default.GetBytes(input);
            string hashName = hashType.ToString();

            PasswordDeriveBytes deriveBytes = new PasswordDeriveBytes(bInput, bSalt, hashName, iterations);

            var b = deriveBytes.GetBytes(keySize);

            return(b.ToBase64UrlString());
        }