当前位置: 首页>>代码示例>>C#>>正文


C# Cryptography.SHA384Managed类代码示例

本文整理汇总了C#中System.Security.Cryptography.SHA384Managed的典型用法代码示例。如果您正苦于以下问题:C# SHA384Managed类的具体用法?C# SHA384Managed怎么用?C# SHA384Managed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SHA384Managed类属于System.Security.Cryptography命名空间,在下文中一共展示了SHA384Managed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHashProvider

        private static HashAlgorithm GetHashProvider(HashProvider hashAlgorithm)
        {
            HashAlgorithm hash;
            switch (hashAlgorithm)
            {
                case HashProvider.SHA1:
                    hash = new SHA1Managed();
                    break;

                case HashProvider.SHA256:
                    hash = new SHA256Managed();
                    break;

                case HashProvider.SHA384:
                    hash = new SHA384Managed();
                    break;

                case HashProvider.SHA512:
                    hash = new SHA512Managed();
                    break;

                case HashProvider.MD5:
                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            return hash;
        }
开发者ID:lamemmv,项目名称:apex,代码行数:29,代码来源:Encryption.cs

示例2: GetHash

        public static string GetHash(string text, string type, Encoding enc, string outputType = null)
        {
            type = type.ToLower();

            byte[] message = enc.GetBytes( text );
            HashAlgorithm algo = null;

            switch (type)
            {
            case "md5":
                algo = new MD5CryptoServiceProvider();
                break;
            case "sha1":
                algo = new SHA1Managed();
                break;
            case "sha256":
                algo = new SHA256Managed();
                break;
            case "sha384":
                algo = new SHA384Managed();
                break;
            case "sha512":
                algo = new SHA512Managed();
                break;
            default:
                throw new ArgumentException("Type must be one of ['md5', 'sha1', 'sha256', 'sha384', 'sha512'].", "type");
            }

            return GetOutput( algo.ComputeHash( message ), outputType );
        }
开发者ID:REMSLogic,项目名称:REMSLogic,代码行数:30,代码来源:Hash.cs

示例3: sha384encrypt

 public static string sha384encrypt(string phrase)
 {
     UTF8Encoding encoder = new UTF8Encoding();
     SHA384Managed sha384hasher = new SHA384Managed();
     byte[] hashedDataBytes = sha384hasher.ComputeHash(encoder.GetBytes(phrase));
     return byteArrayToString(hashedDataBytes);
 }
开发者ID:Ranentil,项目名称:diamonds,代码行数:7,代码来源:Crypto.cs

示例4: GetAlgorithmByFunctionName

 /// <summary>
 /// Every time is created new instance of class to guarantee thread safety
 /// </summary>
 /// <param name="function"></param>
 /// <returns></returns>
 private HashAlgorithm GetAlgorithmByFunctionName(string function)
 {
     HashAlgorithm a;
     switch (Util.Convertion.EnumNameToValue<HashFunction>(function))
     {
         case HashFunction.MD5:
             a = new MD5CryptoServiceProvider();
             break;
         case HashFunction.SHA1:
             a = new SHA1Managed();
             break;
         case HashFunction.SHA256:
             a = new SHA256Managed();
             break;
         case HashFunction.SHA384:
             a = new SHA384Managed();
             break;
         case HashFunction.SHA512:
             a = new SHA512Managed();
             break;
         default:
             throw new ArgumentException("Unknown function", "function");
     }
     return a;
 }
开发者ID:danni95,项目名称:Core,代码行数:30,代码来源:HashProvider.cs

示例5: EncryptPassWord

        /// <summary>
        /// Encrypts the specified password using the specified hash algoritm
        /// </summary>
        /// <param name="passWord"></param>
        /// <param name="salt"></param>
        /// <param name="hashAlgoritm"></param>
        /// <returns></returns>
        public static string EncryptPassWord(string passWord, string salt, HashAlgoritm hashAlgoritm)
        {
            UTF8Encoding textConverter = new UTF8Encoding();
            HashAlgorithm hash;

            switch (hashAlgoritm)
            {
                case HashAlgoritm.SHA1:
                    hash = new SHA1Managed();
                    break;
                case HashAlgoritm.SHA256:
                    hash = new SHA256Managed();
                    break;
                case HashAlgoritm.SHA384:
                    hash = new SHA384Managed();
                    break;
                case HashAlgoritm.SHA512:
                    hash = new SHA512Managed();
                    break;
                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            string tmpPassword = string.Format("{0}_{1}", passWord, salt);
            byte[] passBytes = textConverter.GetBytes(tmpPassword);

            return Convert.ToBase64String(hash.ComputeHash(passBytes));
        }
开发者ID:auxilium,项目名称:JelloScrum,代码行数:36,代码来源:PassWordHelper.cs

示例6: ComputeHash

        /// <summary>
        /// Generates a hash for the given plain text value and returns a
        /// base64-encoded result. Before the hash is computed, a random salt
        /// is generated and appended to the plain text. This salt is stored at
        /// the end of the hash value, so it can be used later for hash
        /// verification.
        /// </summary>
        /// <param name="plainText">
        /// Plaintext value to be hashed. The function does not check whether
        /// this parameter is null.
        /// </param>
        /// <param name="hashAlgorithm">
        /// Name of the hash algorithm. Allowed values are: "MD5", "SHA1",
        /// "SHA256", "SHA384", and "SHA512" (if any other value is specified
        /// MD5 hashing algorithm will be used). This value is case-insensitive.
        /// </param>
        /// <returns>
        /// Hash value formatted as a base64-encoded string.
        /// </returns>
        public static string ComputeHash(string plainText,
                                         HashType hashType)
        {
            // Convert plain text into a byte array.
            var plainTextBytes = Encoding.UTF8.GetBytes(plainText);

            // Allocate array, which will hold plain text.
            var plainTextWithSaltBytes =
                new byte[plainTextBytes.Length];

            // Copy plain text bytes into resulting array.
            for (int i = 0; i < plainTextBytes.Length; i++)
                plainTextWithSaltBytes[i] = plainTextBytes[i];

            // Because we support multiple hashing algorithms, we must define
            // hash object as a common (abstract) base class. We will specify the
            // actual hashing algorithm class later during object creation.
            HashAlgorithm hash;

            // Initialize appropriate hashing algorithm class.
            switch (hashType.ToString())
            {
                case "SHA1":
                    hash = new SHA1Managed();
                    break;

                case "SHA256":
                    hash = new SHA256Managed();
                    break;

                case "SHA384":
                    hash = new SHA384Managed();
                    break;

                case "SHA512":
                    hash = new SHA512Managed();
                    break;

                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            // Compute hash value of our plain text with appended salt.
            var hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

            // Create array which will hold hash and original salt bytes.
            var hashWithSaltBytes = new byte[hashBytes.Length];

            // Copy hash bytes into resulting array.
            for (int i = 0; i < hashBytes.Length; i++)
                hashWithSaltBytes[i] = hashBytes[i];

            // Convert result into a base64-encoded string.
            string hashValue = Convert.ToBase64String(hashWithSaltBytes);

            // Return the result.
            return hashValue;
        }
开发者ID:dvgamer,项目名称:Touno.Sentinel-II,代码行数:78,代码来源:HashUtil.cs

示例7: SetKeyButton_Click

 private void SetKeyButton_Click(object sender, EventArgs e)
 {
     var passwordBytes = Encoding.ASCII.GetBytes(PasswordBox.Text);
     SHA384 sha = new SHA384Managed();
     _cryptor.Key = sha.ComputeHash(passwordBytes);
     EncryptButton.Enabled = true;
     DecryptButton.Enabled = false;
 }
开发者ID:Shanis47,项目名称:MARS_cryptoalgorithm,代码行数:8,代码来源:Cryptor.cs

示例8: SHA384Encrypt

 /// <summary>
 /// SHA384加密,不可逆转
 /// </summary>
 /// <param name="str">string str:被加密的字符串</param>
 /// <returns>返回加密后的字符串</returns>
 public string SHA384Encrypt(string str)
 {
     System.Security.Cryptography.SHA384 s384 = new System.Security.Cryptography.SHA384Managed();
     byte[] byte1;
     byte1 = s384.ComputeHash(Encoding.UTF8.GetBytes(str));
     s384.Clear();
     return Convert.ToBase64String(byte1);
 }
开发者ID:lxh2014,项目名称:gigade-net,代码行数:13,代码来源:HashEncrypt.cs

示例9: SHA384

 public static string SHA384(string data)
 {
     byte[] hash;
     using (SHA384 shaM = new SHA384Managed())
     {
         hash = shaM.ComputeHash(data.GetBytes());
     }
     return AESProvider.HexString(hash);
 }
开发者ID:exaphaser,项目名称:PowerCrypt4,代码行数:9,代码来源:HashUtils.cs

示例10: SHA384Compute

        public static byte[] SHA384Compute(byte[] data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            SHA384Managed SHA384 = new SHA384Managed();
            byte[] hash = SHA384.ComputeHash(data);
            SHA384.Clear();
            return hash;
        }
开发者ID:Steeslice,项目名称:StealthNet-Alt,代码行数:10,代码来源:ComputeHashes.cs

示例11: ComputeHash

        public static string ComputeHash(string plainText, HashAlgorithm hashAlgorithm, string salt)
        {
            System.Security.Cryptography.HashAlgorithm hash;

            switch (hashAlgorithm)
            {
                case HashAlgorithm.SHA1:
                    hash = new SHA1Managed();
                    break;

                case HashAlgorithm.SHA256:
                    hash = new SHA256Managed();
                    break;

                case HashAlgorithm.SHA384:
                    hash = new SHA384Managed();
                    break;

                case HashAlgorithm.SHA512:
                    hash = new SHA512Managed();
                    break;

                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            byte[] saltBytes = Encoding.UTF8.GetBytes(salt);

            byte[] plainTextWithSalt = Encoding.UTF8.GetBytes(plainText + salt);
            byte[] hashBytes = hash.ComputeHash(plainTextWithSalt);
            string hashValue = System.Convert.ToBase64String(hashBytes);

            ////// Compute hash value of our plain text with appended salt.
            //byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

            ////// Create array which will hold hash and original salt bytes.
            //byte[] hashWithSaltBytes = new byte[hashBytes.Length + saltBytes.Length];

            //// Copy hash bytes into resulting array.
            //for (int i = 0; i < hashBytes.Length; i++)
            //{
            //    hashWithSaltBytes[i] = hashBytes[i];
            //}

            //// Append salt bytes to the result.
            //for (int i = 0; i < saltBytes.Length; i++)
            //{
            //    hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];
            //}
            //// Convert result into a base64-encoded string.
            //string hashValue = Convert.ToBase64String(hashWithSaltBytes);

            return hashValue;
        }
开发者ID:RossMerr,项目名称:Redux-Architecture,代码行数:55,代码来源:Hash.cs

示例12: Sha384

        public static string Sha384(string msg)
        {
            if (msg == null)
                return null;

            var encoder = new UTF8Encoding();
            var sha384Hasher = new SHA384Managed();
            var hashedDataBytes = sha384Hasher.ComputeHash(encoder.GetBytes(msg));

            return ByteArrayToString(hashedDataBytes);
        }
开发者ID:kirkpabk,项目名称:higgs,代码行数:11,代码来源:HashFunction.cs

示例13: SHA384Hash

 public static string SHA384Hash(string Paragraph)
 {
     SHA384 sha = new SHA384Managed();
     byte[] hash = sha.ComputeHash(Encoding.ASCII.GetBytes(Paragraph));
     StringBuilder sb = new StringBuilder();
     foreach (byte bt in hash)
     {
         sb.AppendFormat("{0:x2}", bt);
     }
     return sb.ToString();
 }
开发者ID:Celestias,项目名称:CSharp-Tools,代码行数:11,代码来源:Form1.cs

示例14: FromString

        public static string FromString(string input, HashType hashtype)
        {
            Byte[] clearBytes;
            Byte[] hashedBytes;
            string output = String.Empty;

            switch (hashtype)
            {
                case HashType.RIPEMD160:
                    clearBytes = new UTF8Encoding().GetBytes(input);
                    RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create();
                    hashedBytes = myRIPEMD160.ComputeHash(clearBytes);
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.MD5:
                    clearBytes = new UTF8Encoding().GetBytes(input);
                    hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA1:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
                    sha1.ComputeHash(clearBytes);
                    hashedBytes = sha1.Hash;
                    sha1.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA256:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA256 sha256 = new SHA256Managed();
                    sha256.ComputeHash(clearBytes);
                    hashedBytes = sha256.Hash;
                    sha256.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA384:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA384 sha384 = new SHA384Managed();
                    sha384.ComputeHash(clearBytes);
                    hashedBytes = sha384.Hash;
                    sha384.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA512:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA512 sha512 = new SHA512Managed();
                    sha512.ComputeHash(clearBytes);
                    hashedBytes = sha512.Hash;
                    sha512.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
            }
            return output;
        }
开发者ID:nguyenhaiquan,项目名称:trade-software,代码行数:54,代码来源:hashing.cs

示例15: SHA384Hash

        /// <summary>
        /// Encrypts a string using the SHA384(Secure Hash Algorithm) algorithm.
        /// This works in the same manner as MD5, providing 384bit encryption.
        /// </summary>
        /// <param name="Data">A string containing the data to encrypt.</param>
        /// <returns>A string containing the string, encrypted with the SHA384 algorithm.</returns>
        public static string SHA384Hash(string Data)
        {
            SHA384 sha = new SHA384Managed();
            byte[] hash = sha.ComputeHash(Encoding.ASCII.GetBytes(Data));

            StringBuilder stringBuilder = new StringBuilder();
            foreach (byte b in hash)
            {
                stringBuilder.AppendFormat("{0:x2}", b);
            }
            return stringBuilder.ToString();
        }
开发者ID:BGCX262,项目名称:zynchronyze-svn-to-git,代码行数:18,代码来源:CryptoHelper.cs


注:本文中的System.Security.Cryptography.SHA384Managed类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。