• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Cryptography.SHA384Managed类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ComputeHash

 public static string ComputeHash(string plainText,
                          string hashAlgorithm,
                          byte[] saltBytes)
 {
     if (saltBytes == null)
     {
         int minSaltSize = 4;
         int maxSaltSize = 8;
         Random random = new Random();
         int saltSize = random.Next(minSaltSize, maxSaltSize);
         saltBytes = new byte[saltSize];
         RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
         rng.GetNonZeroBytes(saltBytes);
     }
     byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
     byte[] plainTextWithSaltBytes =
             new byte[plainTextBytes.Length + saltBytes.Length];
     for (int i = 0; i < plainTextBytes.Length; i++)
         plainTextWithSaltBytes[i] = plainTextBytes[i];
     for (int i = 0; i < saltBytes.Length; i++)
         plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i];
     HashAlgorithm hash;
     if (hashAlgorithm == null)
         hashAlgorithm = "";
     switch (hashAlgorithm.ToUpper())
     {
         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;
     }
     byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);
     byte[] hashWithSaltBytes = new byte[hashBytes.Length +
                                         saltBytes.Length];
     for (int i = 0; i < hashBytes.Length; i++)
         hashWithSaltBytes[i] = hashBytes[i];
     for (int i = 0; i < saltBytes.Length; i++)
         hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];
     string hashValue = Convert.ToBase64String(hashWithSaltBytes);
     return hashValue;
 }
开发者ID:projectlaser,项目名称:Daydata,代码行数:52,代码来源:MD5Helper.cs


示例17: RijndaelEncryptor

        public RijndaelEncryptor()
        {
            m_key = new byte[32];
            m_vector = new byte[16];

            using (var sha = new SHA384Managed())
            {
                byte[] hashArray = sha.ComputeHash(hashBuffer);

                Array.Copy(hashArray, 0, m_key, 0, 32);
                Array.Copy(hashArray, 32, m_vector, 0, 16);
            }
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:13,代码来源:RijndealEncryptor.cs


示例18: GetSHA384

        public static String GetSHA384(String strPlain)
        {
            UnicodeEncoding UE = new UnicodeEncoding();
            Byte[] HashValue, MessageBytes = UE.GetBytes(strPlain);
            SHA384Managed SHhash = new SHA384Managed();
            String strHex = String.Empty;

            HashValue = SHhash.ComputeHash(MessageBytes);
            foreach (Byte b in HashValue)
            {
                strHex += String.Format("{0:x2}", b);
            }
            return strHex;
        }
开发者ID:paulweatherby,项目名称:Trust,代码行数:14,代码来源:Hasher.cs


示例19: ComputeHash

 public static string ComputeHash(string plainText, HashAlgorithmType hashAlgorithm, bool outputHexFormat)
 {
     HashAlgorithm algorithm;
     plainText = (SALTHash + plainText);
     byte[] bytes = Encoding.UTF8.GetBytes(plainText);
     switch (hashAlgorithm)
     {
         case HashAlgorithmType.SHA1:
             algorithm = new SHA1Managed();
             break;
         case HashAlgorithmType.SHA256:
             algorithm = new SHA256Managed();
             break;
         case HashAlgorithmType.SHA384:
             algorithm = new SHA384Managed();
             break;
         case HashAlgorithmType.SHA512:
             algorithm = new SHA512Managed();
             break;
         default:
             algorithm = new MD5CryptoServiceProvider();
             break;
     }
     byte[] inArray = algorithm.ComputeHash(bytes);
     if (outputHexFormat)
     {
         var builder = new StringBuilder();
         int num2 = (inArray.Length - 1);
         int i = 0;
         while ((i <= num2))
         {
             if ((Conversion.Hex(inArray[i]).Length == 1))
             {
                 builder.Append(("0" + Conversion.Hex(inArray[i])));
             }
             else
             {
                 builder.Append(Conversion.Hex(inArray[i]));
             }
             if ((((i + 1)%2) == 0))
             {
                 builder.Append(" ");
             }
             i++;
         }
         return builder.ToString().Trim().Replace(" ", "-");
     }
     return Convert.ToBase64String(inArray);
 }
开发者ID:preguntoncojonero,项目名称:test,代码行数:49,代码来源:ISHash.cs


示例20: GetFileHash

        public static string GetFileHash(string filePath, HashType type)
        {
            if (!File.Exists(filePath))
                return string.Empty;

            System.Security.Cryptography.HashAlgorithm hasher;
            switch(type)
            {
                case HashType.SHA1:
                default:
                    hasher = new SHA1CryptoServiceProvider();
                    break;
                case HashType.SHA256:
                    hasher = new SHA256Managed();
                    break;
                case HashType.SHA384:
                    hasher = new SHA384Managed();
                    break;
                case HashType.SHA512:
                    hasher = new SHA512Managed();
                    break;
                case HashType.MD5:
                    hasher = new MD5CryptoServiceProvider();
                    break;
                case HashType.RIPEMD160:
                    hasher = new RIPEMD160Managed();
                    break;
            }
            StringBuilder buff = new StringBuilder();
            try
            {
                using (FileStream f = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192))
                {
                    hasher.ComputeHash(f);
                    Byte[] hash = hasher.Hash;
                    foreach (Byte hashByte in hash)
                    {
                        buff.Append(string.Format("{0:x2}", hashByte));
                    }
                }
            }
            catch
            {
                return "Error reading file." + new System.Random(DateTime.Now.Second * DateTime.Now.Millisecond).Next().ToString();
            }
            return buff.ToString();
        }
开发者ID:jorn,项目名称:gitextensions,代码行数:47,代码来源:HashHelper.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cryptography.SHA512Managed类代码示例发布时间:2022-05-26
下一篇:
C# Cryptography.SHA256Managed类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap