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


C# SHA256CryptoServiceProvider.ComputeHash方法代码示例

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


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

示例1: SHA256Encrypt

        public static String SHA256Encrypt(String pwd)
        {
            //Encryption
            //SHA256
            //One-way hash
            //Password Token:
            // (hash(hash(userName+ pwd)+salt))

            String SALT ="buy2easy"; //
            SHA256CryptoServiceProvider provider = new SHA256CryptoServiceProvider();

            // pwd
            Byte[] inputByteArray = Encoding.UTF8.GetBytes(pwd);

            // salt
            Byte[] saltByteArray = Encoding.UTF8.GetBytes(SALT);

            // hash
            Byte[] hashedBytesArray1 = provider.ComputeHash(inputByteArray);

            // Combine salt and input bytes
            Byte[] inputBytesWithSalt = new Byte[hashedBytesArray1.Length + saltByteArray.Length];

            hashedBytesArray1.CopyTo(inputBytesWithSalt, 0);
            saltByteArray.CopyTo(inputBytesWithSalt, hashedBytesArray1.Length);

            // hash again
            Byte[] hashedBytesArray2 = provider.ComputeHash(inputBytesWithSalt);

            // return double hash encrypted string.
            return BitConverter.ToString(hashedBytesArray2);
        }
开发者ID:rnramkumar,项目名称:ToAchu,代码行数:32,代码来源:Customer.cs

示例2: Base58ToByteArray

        public static byte[] Base58ToByteArray(string base58)
        {
            Org.BouncyCastle.Math.BigInteger bi2 = new Org.BouncyCastle.Math.BigInteger("0");
            string b58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

            bool IgnoreChecksum = false;

            foreach (char c in base58)
            {
                if (b58.IndexOf(c) != -1)
                {
                    bi2 = bi2.Multiply(new Org.BouncyCastle.Math.BigInteger("58"));
                    bi2 = bi2.Add(new Org.BouncyCastle.Math.BigInteger(b58.IndexOf(c).ToString()));
                }
                else if (c == '?')
                {
                    IgnoreChecksum = true;
                }
                else
                {
                    return null;
                }
            }

            byte[] bb = bi2.ToByteArrayUnsigned();

            // interpret leading '1's as leading zero bytes
            foreach (char c in base58)
            {
                if (c != '1') break;
                byte[] bbb = new byte[bb.Length + 1];
                Array.Copy(bb, 0, bbb, 1, bb.Length);
                bb = bbb;
            }

            if (bb.Length < 4) return null;

            if (IgnoreChecksum == false)
            {
                SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
                byte[] checksum = sha256.ComputeHash(bb, 0, bb.Length - 4);
                checksum = sha256.ComputeHash(checksum);
                for (int i = 0; i < 4; i++)
                {
                    if (checksum[i] != bb[bb.Length - 4 + i]) return null;
                }
            }

            byte[] rv = new byte[bb.Length - 4];
            Array.Copy(bb, 0, rv, 0, bb.Length - 4);
            return rv;
        }
开发者ID:LawrenceBotley,项目名称:LBitcoin,代码行数:52,代码来源:ReferenceLib.cs

示例3: Hash

 /// <summary>
 /// Hashes the specified arguments.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns>The hash</returns>
 public static string Hash(params object[] args)
 {
     HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();
     byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(String.Concat(args));
     byte[] bytHash = hashAlg.ComputeHash(bytValue);
     return Convert.ToBase64String(bytHash);
 }
开发者ID:IPenkov,项目名称:OnLeave,代码行数:12,代码来源:HashHelper.cs

示例4: GenerateHash

 internal static string GenerateHash(this string input)
 {
     HashAlgorithm hashAlgorithm = new SHA256CryptoServiceProvider();
     var byteValue = System.Text.Encoding.UTF8.GetBytes(input);
     var byteHash = hashAlgorithm.ComputeHash(byteValue);
     return Convert.ToBase64String(byteHash);
 }
开发者ID:warrenbuckley,项目名称:UmbracoIdentity.OAuth,代码行数:7,代码来源:StringExtensions.cs

示例5: GenerateCacheKeyHash

 protected string GenerateCacheKeyHash(int tabId, string cacheKey)
 {
     byte[] hash = Encoding.ASCII.GetBytes(cacheKey);
     var sha256 = new SHA256CryptoServiceProvider();
     hash = sha256.ComputeHash(hash);
     return string.Concat(tabId.ToString(), "_", ByteArrayToString(hash));
 }
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:7,代码来源:OutputCachingProvider.cs

示例6: EncriptarPassword

 private String EncriptarPassword(String password)
 {
     byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
     SHA256 sha256 = new SHA256CryptoServiceProvider();
     byte[] hashedPassword = sha256.ComputeHash(passwordBytes);
     return BitConverter.ToString(hashedPassword).Replace("-","");
 }
开发者ID:castrorodrigo355,项目名称:PagoElectronico,代码行数:7,代码来源:UsuarioBusinessRule.cs

示例7: Encrypt

 public static string Encrypt(string clearText)
 {
     byte[] arrbyte = new byte[clearText.Length];
     SHA256 hash = new SHA256CryptoServiceProvider();
     arrbyte = hash.ComputeHash(Encoding.UTF8.GetBytes(clearText));
     return Convert.ToBase64String(arrbyte);
 }
开发者ID:vc3,项目名称:LeisureStar,代码行数:7,代码来源:Encryption.cs

示例8: Signature

 public static void Signature(Stream input, Stream output, string privateKey)
 {
     using (var sha = new SHA256CryptoServiceProvider())
     using (var rsa = new RSACryptoServiceProvider())
     {
         // Compute hash
         var buffer = ReadAllBytes(input);
         var hash = sha.ComputeHash(buffer);
         // RSA Initialize
         rsa.FromXmlString(privateKey);
         // format
         var formatter = new RSAPKCS1SignatureFormatter(rsa);
         formatter.SetHashAlgorithm("SHA256");
         var signature = formatter.CreateSignature(hash);
         // Krile Signature Package
         var magic = MagicStr + ":" + signature.Length + ":";
         var magicbytes = Encoding.UTF8.GetBytes(magic);
         if (magicbytes.Length > 64)
             throw new Exception("Magic bits too long.");
         output.Write(magicbytes, 0, magicbytes.Length);
         var padding = new byte[64 - magicbytes.Length];
         output.Write(padding, 0, padding.Length);
         output.Write(signature, 0, signature.Length);
         output.Write(buffer, 0, buffer.Length);
     }
 }
开发者ID:Kei-Nanigashi,项目名称:StarryEyes,代码行数:26,代码来源:Cryptography.cs

示例9: CreateDoctorAcccount

        public string CreateDoctorAcccount(string email, string dname, string pwd, string cfmpwd, string mobileno, string dob, string pip)
        {
            if (dname.Length == 0)
                returnMessage += "Therapist Name cannot be blank <br />";
            if (pwd.Length == 0)
                returnMessage += "Password cannot be blank <br/>";
            if (cfmpwd.Length == 0)
                returnMessage += "Cofirm Passowrd cannot be blank <br/>";
            if (mobileno.Length == 0)
                returnMessage += "Mobile Number cannot be blank <br/>";
            if (dob.Length == 0)
                returnMessage += "Date of Birth cannnot be blank <br/>";
            if (pip.Length == 0)
                returnMessage += "Please Upload an image <br/>";
            if (pwd != cfmpwd)
                returnMessage += "Your passwords dont match <br/>";

            if (returnMessage.Length == 0)
            {
                SHA256 sha = new SHA256CryptoServiceProvider();
                byte[] data = Encoding.ASCII.GetBytes(pwd);
                byte[] result = sha.ComputeHash(data);
                string hashedpwd = Convert.ToBase64String(result);
                AzureUserDAL doc = new AzureUserDAL(email, dname, hashedpwd, mobileno, dob, pip);
                int noofRows = 0;
                noofRows = doc.CreateDoctorProfile();

                if (noofRows > 0)
                    returnMessage = "You Signed Up Succuesfully.";
                else
                    returnMessage = "Error,Please try again";

            }
            return returnMessage;
        }
开发者ID:Sherazzie,项目名称:MusicTherapyProject,代码行数:35,代码来源:AzureUserBLL.cs

示例10: HashStringSHA256

 public static string HashStringSHA256(string valueUTF8)
 {
     byte[] valueBytes = Encoding.UTF8.GetBytes(valueUTF8);
     SHA256CryptoServiceProvider shar2 = new SHA256CryptoServiceProvider();
     byte[] hashBytes = shar2.ComputeHash(valueBytes);
     return BitConverter.ToString(hashBytes).Replace("-", "");
 }
开发者ID:GrowingData,项目名称:Mung,代码行数:7,代码来源:Hashing.cs

示例11: GenerateToken

        public static string GenerateToken(string @namespace, string eventHub, string publisher, string sharedAccessKeyName, string sharedAccessKey, DateTimeOffset expiry)
        {
            var unixEpoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
            var timeSinceEpoch = expiry - unixEpoch;
            var timeSinceEpochInMilliseconds = (long)timeSinceEpoch.TotalMilliseconds;

            var url = Helper.BuildUrl(@namespace, eventHub, publisher);
            var encodedUrl = HttpUtility.UrlEncode(url);
            var signatureContent = string.Format("{0}\n{1}", encodedUrl, timeSinceEpochInMilliseconds);

            var signatureContentAsBytes = Encoding.UTF8.GetBytes(signatureContent);
            var provider = new SHA256CryptoServiceProvider();
            var signatureAsBytes = provider.ComputeHash(signatureContentAsBytes);
            var signature = Convert.ToBase64String(signatureAsBytes);

            var token = string.Format(
                "sr={0}&sig={1}&se={2}&skn={3}",
                HttpUtility.UrlEncode(url),
                HttpUtility.UrlEncode(signature),
                timeSinceEpochInMilliseconds,
                HttpUtility.UrlEncode(sharedAccessKeyName)
                );

            return token;
        }
开发者ID:mitchdenny,项目名称:azure-eventhubs-performance,代码行数:25,代码来源:Helper.cs

示例12: Hash

 public static string Hash(this string clear_text)
 {
     using (HashAlgorithm hash = new SHA256CryptoServiceProvider())
     {
         return Convert.ToBase64String(hash.ComputeHash(Encoding.UTF8.GetBytes(clear_text)));
     }
 }
开发者ID:HKStrategies,项目名称:countrywide-countdown,代码行数:7,代码来源:Extensions.cs

示例13: SHA256

 public static string SHA256(string str)
 {
     byte[] buffer = Encoding.UTF8.GetBytes(str);
     SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider();
     byte[] byteArr = SHA256.ComputeHash(buffer);
     return BitConverter.ToString(byteArr);
 }
开发者ID:chinayinhui,项目名称:LYLQ,代码行数:7,代码来源:CryptographyHelper.cs

示例14: HashPassword

        private NewPassword HashPassword(NewPassword np)
        {
            HashAlgorithm hashAlg = null;

            try
            {
                hashAlg = new SHA256CryptoServiceProvider();
                byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(np.GetSaltPassword());
                byte[] bytHash = hashAlg.ComputeHash(bytValue);
                np.SaltedHashedPassword = Convert.ToBase64String(bytHash);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (hashAlg != null)
                {
                    hashAlg.Clear();
                    hashAlg.Dispose();
                    hashAlg = null;
                }
            }

            return np;
        }
开发者ID:ehelin,项目名称:TGIMBA,代码行数:27,代码来源:Password.cs

示例15: HashPassword

        public static string HashPassword(string password, string saltValue)
        {
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Password is null");

            var encoding = new UnicodeEncoding();
            var hash = new SHA256CryptoServiceProvider();

            if (saltValue == null)
            {
                saltValue = GenerateSaltValue();
            }

            byte[] binarySaltValue = Convert.FromBase64String(saltValue);
            byte[] valueToHash = new byte[SaltValueSize + encoding.GetByteCount(password)];
            byte[] binaryPassword = encoding.GetBytes(password);

            binarySaltValue.CopyTo(valueToHash, 0);
            binaryPassword.CopyTo(valueToHash, SaltValueSize);

            byte[] hashValue = hash.ComputeHash(valueToHash);
            var hashedPassword = String.Empty;
            foreach (byte hexdigit in hashValue)
            {
                hashedPassword += hexdigit.ToString("X2", CultureInfo.InvariantCulture.NumberFormat);
            }

            return hashedPassword;
        }
开发者ID:Kirichenko-sanek,项目名称:SocialNetwork,代码行数:28,代码来源:PasswornHashing.cs


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