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


C# Cryptography.SHA256CryptoServiceProvider类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: GetHashProvider

 public static HashAlgorithm GetHashProvider(HashType type)
 {
     HashAlgorithm hash = null;
     switch (type)
     {
         case HashType.MD5:
             {
                 hash = new MD5CryptoServiceProvider();
                 break;
             }
         case HashType.SHA1:
             {
                 hash = new SHA1CryptoServiceProvider();
                 break;
             }
         case HashType.SHA256:
             {
                 hash = new SHA256CryptoServiceProvider();
                 break;
             }
         case HashType.SHA384:
             {
                 hash = new SHA384CryptoServiceProvider();
                 break;
             }
         case HashType.SHA512:
             {
                 hash = new SHA512CryptoServiceProvider();
                 break;
             }
     }
     return hash;
 }
开发者ID:kLeZ,项目名称:Gecko,代码行数:33,代码来源:MD5SHAHelper.cs

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例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: CreateHashedPassword

 public static string CreateHashedPassword(string password, string salt)
 {
     var sha256 = new SHA256CryptoServiceProvider();
     byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(password + salt);
     byte[] hashedPasswordBytes = sha256.ComputeHash(passwordBytes);
     return Convert.ToBase64String(hashedPasswordBytes);
 }
开发者ID:marcelopuppin,项目名称:MicropostMVC,代码行数:7,代码来源:Encryptor.cs


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