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

C# Cryptography.SHA256Managed类代码示例

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

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



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

示例1: HashValues

        private string HashValues(string Value1, string Value2, string HashingAlgorithm)
        {
            string sHashingAlgorithm = "";
            if (String.IsNullOrEmpty(HashingAlgorithm))
                sHashingAlgorithm = "SHA-1";
            else
                sHashingAlgorithm = HashingAlgorithm;

            byte[] arrByte;

            if (sHashingAlgorithm == "SHA-1")
            {
                SHA1Managed hash = new SHA1Managed();
                arrByte = hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Value1 + Value2));
            }
            else
            {
                SHA256Managed hash = new SHA256Managed();
                arrByte = hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Value1 + Value2));
            }

            string s = "";
            for (int i = 0; i < arrByte.Length; i++)
            {
                s += arrByte[i].ToString("x2");
            }
            return s;
        }
开发者ID:ArfiSoft,项目名称:MSoHelpDesk,代码行数:28,代码来源:KaseyaHelper.cs


示例2: GenerateSaltedHash

        public static string GenerateSaltedHash(string userName, string pssWd)
        {
            if (userName ==null || pssWd == null)
            {
                return null;
            }
            byte[] userNameBytes = GetBytes(userName);
            byte[] pssWdBytes = GetBytes(pssWd);
            HashAlgorithm algorithm = new SHA256Managed();

            byte[] plainTextWithSaltBytes =
              new byte[userNameBytes.Length + pssWdBytes.Length];

            for (int i = 0; i < userNameBytes.Length; i++)
            {
                plainTextWithSaltBytes[i] = userNameBytes[i];
            }
            for (int i = 0; i < pssWdBytes.Length; i++)
            {
                plainTextWithSaltBytes[userNameBytes.Length + i] = pssWdBytes[i];
            }

            byte[] hash = algorithm.ComputeHash(plainTextWithSaltBytes);
            StringBuilder sBuilder = new StringBuilder();

            for (int i = 0; i < hash.Length; i++)
            {
                sBuilder.Append(hash[i].ToString("x2"));
            }

            return sBuilder.ToString();
        }
开发者ID:ekople,项目名称:VR2,代码行数:32,代码来源:Utils.cs


示例3: SHA256

 public static String SHA256(String text)
 {
     UTF8Encoding encoder = new UTF8Encoding();
     SHA256Managed sha256hasher = new SHA256Managed();
     byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(text));
     return System.Convert.ToBase64String(hashedDataBytes);
 }
开发者ID:codaxy,项目名称:common,代码行数:7,代码来源:Cryptography.cs


示例4: GetBundleVirtualPath

        protected virtual string GetBundleVirtualPath(string prefix, string postfix, string[] parts)
        {
            if (parts == null || parts.Length == 0)
                throw new ArgumentException("parts");

            //calculate hash
            var hash = "";
            using (SHA256 sha = new SHA256Managed())
            {
                // string concatenation
                var hashInput = "";
                foreach (var part in parts)
                {
                    hashInput += part;
                    hashInput += ",";
                }

                byte[] input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput));
                hash = HttpServerUtility.UrlTokenEncode(input);
            }
            //ensure only valid chars
            hash = SeoExtensions.GetSeName(hash);

            var sb = new StringBuilder(prefix);
            sb.Append(hash);
            sb.Append(postfix);
            return sb.ToString();
        }
开发者ID:haithemChkel,项目名称:nopCommerce_33,代码行数:28,代码来源:PageHeadBuilder.cs


示例5: EncryptUserPassword

        /// <summary>
        /// Encrypts the user's password
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public string EncryptUserPassword(string password)
        {
            //return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");

            string salt = GenerateSalt();

            //start hash creation:
            System.Security.Cryptography.SHA256 sha256 = new System.Security.Cryptography.SHA256Managed();

            // password string to bytes
            byte[] sha256Bytes = System.Text.Encoding.UTF8.GetBytes(password);

            //password bytes to hash
            byte[] cryString = sha256.ComputeHash(sha256Bytes);

            // start final encrypted password
            string sha256Str = string.Empty;

            // create final encrypted password: bytes to hex string
            for (int i = 0; i < cryString.Length; i++)
            {
                sha256Str += cryString[i].ToString("X");
            }

            // concatenate hashed password + salt
            // sha256Str = sha256Str + salt;

            return sha256Str;
        }
开发者ID:ChrisNelsonPE,项目名称:surveyproject_main_public,代码行数:34,代码来源:User.cs


示例6: SHA256

 /// <summary>
 /// SHA256函数
 /// </summary>
 /// /// <param name="str">原始字符串</param>
 /// <returns>SHA256结果</returns>
 public static string SHA256(string str)
 {
     byte[] SHA256Data = Encoding.UTF8.GetBytes(str);
     SHA256Managed Sha256 = new SHA256Managed();
     byte[] Result = Sha256.ComputeHash(SHA256Data);
     return Convert.ToBase64String(Result);  //返回长度为44字节的字符串
 }
开发者ID:robotbird,项目名称:jqpress,代码行数:12,代码来源:EncryptHelper.cs


示例7: Sha256

 public static string Sha256(string password)
 {
     SHA256Managed crypt = new SHA256Managed();
     string hash = String.Empty;
     byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0, Encoding.UTF8.GetByteCount(password));
     return crypto.Aggregate(hash, (current, bit) => current + bit.ToString("x2"));
 }
开发者ID:sczk,项目名称:collab-project,代码行数:7,代码来源:Hash.cs


示例8: GetHashSha256

 public string GetHashSha256(string token)
 {
     var bytes = Encoding.UTF8.GetBytes(token);
     var hasher = new SHA256Managed();
     var hash = hasher.ComputeHash(bytes);
     return hash.Aggregate(string.Empty, (current, x) => current + string.Format("{0:x2}", x));
 }
开发者ID:olehkrut,项目名称:WorldOfWords,代码行数:7,代码来源:TokenValidation.cs


示例9: Encrypt

        public static byte[] Encrypt(byte[] payload, CryptoContext cryptoContext)
        {
            var csEncrypt = cryptoContext.CryptoStreamOut;
            var output = cryptoContext.OutputStream;
            output.Position = 0;
            output.SetLength(0);

            using (MemoryStream hashStream = new MemoryStream())
            {
                // hash

                SHA256Managed crypt = new SHA256Managed();

                hashStream.Write(BitConverter.GetBytes(Interlocked.Increment(ref cryptoContext.SendCounter)), 0, 8);
                hashStream.Write(payload, 0, payload.Length);
                hashStream.Write(cryptoContext.Algorithm.Key, 0, cryptoContext.Algorithm.Key.Length);
                var hashBuffer = hashStream.ToArray();

                byte[] validationCheckSum = crypt.ComputeHash(hashBuffer, 0, hashBuffer.Length);

                byte[] content = payload.Concat(validationCheckSum.Take(8)).ToArray();

                csEncrypt.Write(content, 0, content.Length);
                csEncrypt.Flush();
            }

            return output.ToArray();
        }
开发者ID:GoldishKirby,项目名称:MiNET,代码行数:28,代码来源:CryptoUtils.cs


示例10: Server

 /// <summary>
 /// konstruktor obiektu Server 
 /// </summary>
 public Server()
 {
     requestReceived += Server_requestReceived;
     aesKeyGenerator = new AesManaged();
     hashAlgorithm = new SHA256Managed();
     rsaKeyGenerator = new RSACryptoServiceProvider();      
 }
开发者ID:Kubabanka,项目名称:PKRY_15Z_Komunikator,代码行数:10,代码来源:Server.cs


示例11: HexSha256

        public static string HexSha256(string text)
        {
            const string salt = "jk#=¤)\"gld\"2347X#Z472\\!";
            var hash = new SHA256Managed().ComputeHash(Encoding.ASCII.GetBytes(text + salt));

            return hash.Aggregate("", (current, x) => current + string.Format("{0:x2}", x));
        }
开发者ID:creodeus,项目名称:SystemOverWatch,代码行数:7,代码来源:Hash.cs


示例12: checkPassword

        //this method checks that passwords match in a login attempt
        public bool checkPassword()
        {
            Credentials userCredentials = SecurityUserDAO.getUserCredentials(username);
            if (userCredentials != null)
            {
                byte[] dbPass = Convert.FromBase64String(userCredentials.getPassword());

                byte[] userPass = createByteArrayFromString(password);
                byte[] dbSalt = createByteArrayFromString(userCredentials.getSalt());

                byte[] userSaltedPass = userPass.Concat(dbSalt).ToArray();

                HashAlgorithm algorithm = new SHA256Managed();
                byte[] hasheduserPass = algorithm.ComputeHash(userSaltedPass);

                bool match = compareByteArrays(dbPass, hasheduserPass);
                if (match)
                {
                    userId = userCredentials.getUserId();
                }
                return match;
            }
            else
            {
                return false;
            }
        }
开发者ID:craig-smith,项目名称:CISSeniorProjectFinal,代码行数:28,代码来源:PasswordManager.cs


示例13: SHA256

 public static byte[] SHA256(byte[] data, int offset, int count)
 {
     using (var sha = new SHA256Managed())
     {
         return sha.ComputeHash(data, offset, count);
     }
 }
开发者ID:lontivero,项目名称:BitcoinLite,代码行数:7,代码来源:Hashes.cs


示例14: FromByteArray

 public static String FromByteArray(Byte[] b, Byte version)
 {
     SHA256 sha256 = new SHA256Managed();
     b = (new Byte[] { version }).Concat(b).ToArray();
     Byte[] hash = sha256.ComputeHash(sha256.ComputeHash(b)).Take(4).ToArray();
     return Base58String.FromByteArray(b.Concat(hash).ToArray());
 }
开发者ID:LawrenceBotley,项目名称:LBitcoin,代码行数:7,代码来源:Base58CheckString.cs


示例15: SHA256

 /// <summary>
 ///     SHA256º¯Êý
 /// </summary>
 /// ///
 /// <param name="str">ԭʼ×Ö·û´®</param>
 /// <returns>SHA256½á¹û</returns>
 public static string SHA256(string str)
 {
     var SHA256Data = Encoding.UTF8.GetBytes(str);
     var Sha256 = new SHA256Managed();
     var Result = Sha256.ComputeHash(SHA256Data);
     return Convert.ToBase64String(Result); //·µ»Ø³¤¶ÈΪ44×Ö½ÚµÄ×Ö·û´®
 }
开发者ID:lirongjun0926,项目名称:Farseer.Net,代码行数:13,代码来源:Encrypt.cs


示例16: SHA256

 public static byte[] SHA256(string str)
 {
     SHA256 sha = new SHA256Managed();
     sha.Initialize();
     //return sha.ComputeHash(str.ToByteArray());
     return sha.ComputeHash(Encoding.UTF8.GetBytes(str));
 }
开发者ID:apeape,项目名称:Cheeeeeeeeese,代码行数:7,代码来源:Crypto.cs


示例17: ComputeHashString

 protected string ComputeHashString(string rawString)
 {
     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
     SHA256 hashM = new SHA256Managed();
     return encoding.GetString(hashM.ComputeHash(encoding.GetBytes(rawString))).
         Replace(',', '.').Replace('\r', '.').Replace('\n', '.');
 }
开发者ID:ne-sachirou,项目名称:yUsin-1,代码行数:7,代码来源:DatasData.cs


示例18: sha256Hash

 public static string sha256Hash(string strToHash)
 {
     SHA256Managed crypt = new SHA256Managed();
     string hash = String.Empty;
     byte[] crypto = crypt.ComputeHash(Encoding.ASCII.GetBytes(strToHash), 0, Encoding.ASCII.GetByteCount(strToHash));
     return crypto.Aggregate(hash, (current, theByte) => current + theByte.ToString("x2"));
 }
开发者ID:CIS-Summerside,项目名称:CIS2261-Final-Project,代码行数:7,代码来源:HashingTools.cs


示例19: DevEditPost

 public ActionResult DevEditPost(DevEditViewModel editVm)
 {
     var repo = new Repository();
     var original = GetDevEditViewModel(editVm.Id);
     original.Message = editVm.Message;
     var asc = new WebClient().DownloadData(repo.GetASCLink(editVm.Id));
     string extracted;
     if(!CryptoHelper.VerifySig(asc, editVm.Message, out extracted))
     {
         ModelState.AddModelError("Message", "Incorrectly signed");
     }
     else
     {
         byte[] hash = null;
         using(SHA256 sha = new SHA256Managed())
         {
             hash = sha.ComputeHash(Encoding.UTF8.GetBytes(extracted));
         }
         if(repo.SaveHash(hash))
         {
             repo.UpdateDevViewModel(original);
             return RedirectToAction("Dev", "Main", new
             {
                 devId = editVm.Id
             });
         }
         else
         {
             ModelState.AddModelError("Message", "You can't replay an old message");
         }
     }
     return View("DevEdit", original);
 }
开发者ID:NicolasDorier,项目名称:BIPxDevs,代码行数:33,代码来源:MainController.cs


示例20: Sha256Hash

 public static string Sha256Hash(byte[] ba)
 { 
     SHA256Managed sha2 = new SHA256Managed();
     byte[] ba2 = sha2.ComputeHash(ba);
     sha2 = null;
     return BitConverter.ToString(ba2).Replace("-", string.Empty).ToLower();
 }
开发者ID:njmube,项目名称:Mysqlbackup.net,代码行数:7,代码来源:CryptoExpress.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Cryptography.SHA384Managed类代码示例发布时间:2022-05-26
下一篇:
C# Cryptography.SHA256CryptoServiceProvider类代码示例发布时间: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