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

C# Cryptography.SHA1CryptoServiceProvider类代码示例

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

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



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

示例1: Sha1

 public static string Sha1(string text)
 {
     byte[] buffer = Encoding.UTF8.GetBytes(text);
     SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
     byte[] outbuffer = cryptoTransformSHA1.ComputeHash(buffer);
     return Convert.ToBase64String(outbuffer);
 }
开发者ID:fernandolozer,项目名称:Jetfuel-CSharp,代码行数:7,代码来源:CryptoHelper.cs


示例2: Sha1Hash

 /// <summary>
 /// Gets the SHA1 hash of a string.
 /// </summary>
 /// <param name="str">The string to be hashed.</param>
 /// <returns>The Base64 hashed value.</returns>
 public static string Sha1Hash(this string str)
 {
     using (var sha1 = new SHA1CryptoServiceProvider())
     {
         return Convert.ToBase64String(sha1.ComputeHash(Encoding.ASCII.GetBytes(str)));
     }
 }
开发者ID:chrisdavies,项目名称:Christophilus,代码行数:12,代码来源:StringEx.cs


示例3: ComputeFileHash

 internal static byte[] ComputeFileHash(byte[] fileBytes)
 {
     using (var sha1 = new SHA1CryptoServiceProvider())
     {
         return sha1.ComputeHash(fileBytes);
     }
 }
开发者ID:AnchoretTeam,项目名称:AppUpdate,代码行数:7,代码来源:FileHashHelper.cs


示例4: TripleDESKeyWrapEncrypt

        //
        // internal static methods
        //

        // CMS TripleDES KeyWrap as described in "http://www.w3.org/2001/04/xmlenc#kw-tripledes"
        internal static byte[] TripleDESKeyWrapEncrypt (byte[] rgbKey, byte[] rgbWrappedKeyData) {
            // checksum the key
            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
            byte[] rgbCKS = sha.ComputeHash(rgbWrappedKeyData);

            // generate a random IV
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] rgbIV = new byte[8];
            rng.GetBytes(rgbIV);

            // rgbWKCS = rgbWrappedKeyData | (first 8 bytes of the hash)
            byte[] rgbWKCKS = new byte[rgbWrappedKeyData.Length + 8];
            TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
            // Don't add padding, use CBC mode: for example, a 192 bits key will yield 40 bytes of encrypted data
            tripleDES.Padding = PaddingMode.None;
            ICryptoTransform enc1 = tripleDES.CreateEncryptor(rgbKey, rgbIV);
            Buffer.BlockCopy(rgbWrappedKeyData, 0, rgbWKCKS, 0, rgbWrappedKeyData.Length);
            Buffer.BlockCopy(rgbCKS, 0, rgbWKCKS, rgbWrappedKeyData.Length, 8);
            byte[] temp1 = enc1.TransformFinalBlock(rgbWKCKS, 0, rgbWKCKS.Length);
            byte[] temp2 = new byte[rgbIV.Length + temp1.Length];
            Buffer.BlockCopy(rgbIV, 0, temp2, 0, rgbIV.Length);
            Buffer.BlockCopy(temp1, 0, temp2, rgbIV.Length, temp1.Length);
            // temp2 = REV (rgbIV | E_k(rgbWrappedKeyData | rgbCKS))
            Array.Reverse(temp2);

            ICryptoTransform enc2 = tripleDES.CreateEncryptor(rgbKey, s_rgbTripleDES_KW_IV);
            return enc2.TransformFinalBlock(temp2, 0, temp2.Length);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:33,代码来源:SymmetricKeyWrap.cs


示例5: Main

		public static void Main(string[] args)
		{
			// Use Release Build to use jsc to generate java program
			// Use Debug Build to develop on .net

			// doubleclicking on the jar will not show the console

			{
				Console.WriteLine("SHA1:");
				var hash = new SHA1CryptoServiceProvider().ComputeHash(new byte[] { 0, 1, 2, 3 });

				foreach (var k in hash)
				{
					Console.Write(" " + k);
				}
				Console.WriteLine();
			}

			{
				Console.WriteLine("MD5:");
				var hash = new MD5CryptoServiceProvider().ComputeHash(new byte[] { 0, 1, 2, 3 });

				foreach (var k in hash)
				{
					Console.Write(" " + k);
				}
				Console.WriteLine();
			}

			Console.ReadLine();
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:31,代码来源:Program.cs


示例6: SHA1File

 public static string SHA1File(FileInfo fileInfo)
 {
     using (SHA1 sha1 = new SHA1CryptoServiceProvider())
     {
         return FileHash(fileInfo, sha1);
     }
 }
开发者ID:isakkarlsson,项目名称:iphonebackupbrowser-enhanced,代码行数:7,代码来源:Util.cs


示例7: Sign

        private byte[] Sign(SHA1CryptoServiceProvider hash)
        {
            var formatter = new RSAPKCS1SignatureFormatter(_certificate.PrivateKey).
                Tap(it => it.SetHashAlgorithm("MD5"));

            return formatter.CreateSignature(hash);
        }
开发者ID:ChrisRomp,项目名称:Xero-Net,代码行数:7,代码来源:RsaSha1.cs


示例8: GenarateSinature

        public static int GenarateSinature(string sToken, string sTimeStamp, string sNonce, string sMsgEncrypt, ref string sMsgSignature)
        {
            ArrayList AL = new ArrayList();
            AL.Add(sToken);
            AL.Add(sTimeStamp);
            AL.Add(sNonce);
            AL.Add(sMsgEncrypt);
            AL.Sort(new DictionarySort());
            string raw = "";
            for (int i = 0; i < AL.Count; ++i)
            {
                raw += AL[i];
            }

            SHA1 sha;
            ASCIIEncoding enc;
            string hash = "";
            try
            {
                sha = new SHA1CryptoServiceProvider();
                enc = new ASCIIEncoding();
                byte[] dataToHash = enc.GetBytes(raw);
                byte[] dataHashed = sha.ComputeHash(dataToHash);
                hash = BitConverter.ToString(dataHashed).Replace("-", "");
                hash = hash.ToLower();
            }
            catch (Exception)
            {
                return (int)WXBizMsgCryptErrorCode.WXBizMsgCrypt_ComputeSignature_Error;
            }
            sMsgSignature = hash;
            return 0;
        }
开发者ID:newlysoft,项目名称:WeiXinSDK-1,代码行数:33,代码来源:WXBizMsgCrypt.cs


示例9: Sha1EncryptPassword

 /// <summary>
 /// Хэширует текст
 /// </summary>
 /// <param name="phrase"></param>
 /// <returns></returns>
 public static string Sha1EncryptPassword(string phrase)
 {
     var encoder = new UTF8Encoding();
     var sha1Hasher = new SHA1CryptoServiceProvider();
     var hashedDataBytes = sha1Hasher.ComputeHash(encoder.GetBytes(phrase));
     return ByteArrayToString(hashedDataBytes);
 }
开发者ID:gerasyana,项目名称:Academy,代码行数:12,代码来源:PasswordHelper.cs


示例10: ComputeChecksum

        /// <summary> Private method used to calculate the sha1 check summ</summary>
        private void ComputeChecksum()
        {
            try
            {
                FileStream hashFile = new FileStream(fileName, FileMode.Open, FileAccess.Read);

                SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
                byte[] result = sha1.ComputeHash(hashFile);

                hashFile.Close();

                string buffer = "";
                foreach (byte thisByte in result)
                {
                    if (thisByte < 16)
                    {
                        buffer += "0" + thisByte.ToString("x");
                    }
                    else
                    {
                        buffer += thisByte.ToString("x");
                    }
                }
                hashResult = buffer;

                errorFlag = false;
            }
            catch
            {
                hashResult = "ERROR";
                errorFlag = true;
            }
        }
开发者ID:Elkolt,项目名称:SobekCM-Web-Application,代码行数:34,代码来源:FileSHA1.cs


示例11: GetSHA1Checksum

 public static string GetSHA1Checksum(byte[] inBytes)
 {
     using (SHA1CryptoServiceProvider _sha1CryptoServiceProvider = new SHA1CryptoServiceProvider())
     {
         return BitConverter.ToString(_sha1CryptoServiceProvider.ComputeHash(inBytes));
     }
 }
开发者ID:ighristov,项目名称:VersionUpdater,代码行数:7,代码来源:FileManager.cs


示例12: sha1encrypt

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


示例13: Sha1Encrypt

 /// <summary>
 /// SHA1加密 使用缺省密钥给字符串加密
 /// </summary>
 /// <param name="sourceString"></param>
 /// <returns></returns>
 public static string Sha1Encrypt(string sourceString)
 {
     var data = Encoding.Default.GetBytes(sourceString);
     HashAlgorithm sha = new SHA1CryptoServiceProvider();
     var bytes = sha.ComputeHash(data);
     return BitConverter.ToString(bytes).Replace("-", "");
 }
开发者ID:wukejiong,项目名称:jiongNote,代码行数:12,代码来源:CryptHelper.cs


示例14: Hash

 private static string Hash(byte[] clearBuffer, HashAlgorithm algorithm)
 {
     System.Security.Cryptography.HashAlgorithm hashAlgorithm;
     switch (algorithm)
     {
         case HashAlgorithm.MD5:
             hashAlgorithm = new MD5CryptoServiceProvider();
             break;
         case HashAlgorithm.SHA1:
         default:
             hashAlgorithm = new SHA1CryptoServiceProvider();
             break;
         case HashAlgorithm.SHA256:
             hashAlgorithm = new SHA256CryptoServiceProvider();
             break;
         case HashAlgorithm.SHA384:
             hashAlgorithm = new SHA384CryptoServiceProvider();
             break;
         case HashAlgorithm.SHA512:
             hashAlgorithm = new SHA512CryptoServiceProvider();
             break;
     }
     var encryptedBuffer = hashAlgorithm.ComputeHash(clearBuffer);
     return Convert.ToBase64String(encryptedBuffer);
 }
开发者ID:gosuto,项目名称:tfs2.com,代码行数:25,代码来源:Crypto.cs


示例15: Main

        static void Main(string[] args)
        {
            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();

            Console.Write("Enter username: ");
            string username = Console.ReadLine().ToUpper();
            Console.Write("Enter password: ");
            string password = Console.ReadLine().ToUpper();

            string temp = username + ":" + password;

            byte[] temp2 = Encoding.ASCII.GetBytes(temp);

            sha.ComputeHash(temp2, 0, temp2.Length);

            string hash = String.Empty;

            for (int i = 0; i < sha.Hash.Length; i++)
            {
                hash += sha.Hash[i].ToString("X2");
            }

            Console.WriteLine("Hash: {0}", hash);
            Console.ReadKey();
        }
开发者ID:frostmourne,项目名称:toms_tools,代码行数:25,代码来源:Program.cs


示例16: CerRSAVerifySignature

 /// <summary>
 /// 引用证书非对称加/解密RSA-公钥验签【OriginalString:原文;SignatureString:签名字符;pubkey_path:证书路径;CertificatePW:证书密码;SignType:签名摘要类型(1:MD5,2:SHA1)】
 /// </summary>
 public static bool CerRSAVerifySignature(string OriginalString, string SignatureString, string pubkey_path, string CertificatePW, int SignType)
 {
     byte[] OriginalByte = System.Text.Encoding.UTF8.GetBytes(OriginalString);
     byte[] SignatureByte = Convert.FromBase64String(SignatureString);
     X509Certificate2 x509_Cer1 = new X509Certificate2(pubkey_path, CertificatePW);
     RSACryptoServiceProvider rsapub = (RSACryptoServiceProvider)x509_Cer1.PublicKey.Key;
     rsapub.ImportCspBlob(rsapub.ExportCspBlob(false));
     RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsapub);
     byte[] HashData;
     switch (SignType)
     {
         case 1:
             f.SetHashAlgorithm("MD5");//摘要算法MD5
             MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
             HashData = md5.ComputeHash(OriginalByte);
             break;
         default:
             f.SetHashAlgorithm("SHA1");//摘要算法SHA1
             SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
             HashData = sha.ComputeHash(OriginalByte);
             break;
     }
     if (f.VerifySignature(HashData, SignatureByte))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
开发者ID:jxzly229190,项目名称:OnlineStore,代码行数:34,代码来源:99BillController.cs


示例17: CreateAuthResponse

        public static RealmPacket CreateAuthResponse(String name, String password)
        {
            SHA1 sha = new SHA1CryptoServiceProvider();
            byte[] user_pass = System.Text.Encoding.UTF8.GetBytes(((name + ":" + password).ToCharArray()));
            byte[] hash = sha.ComputeHash(user_pass);
            byte[] salt = new byte[32];
            new Random().NextBytes(salt);
            byte[] result = new byte[hash.Length + salt.Length];
            hash.CopyTo(result, 0);
            salt.CopyTo(result, hash.Length);
            byte[] finalhash = sha.ComputeHash(result);

            byte[] rand = new byte[20];
            new Random().NextBytes(rand);
            //BigInteger int_a = new BigInteger(reverse(finalhash));
            //BigInteger int_b = new BigInteger(reverse(N));
            BigInteger int_c = new BigInteger(new Byte[] { 7 });
            BigInteger int_d = int_c.modPow(new BigInteger(reverse(finalhash)),new BigInteger(reverse(N)));

            BigInteger K = new BigInteger(new Byte[] { 3 });
            BigInteger temp = ((K * int_d) + int_c.modPow(new BigInteger(reverse(rand)), new BigInteger(reverse(N)))) % new BigInteger(reverse(N));

            RealmPacket response = new RealmPacket();
            response.opcode = RealmOpcode.RS_AUTH_LOGON_CHALLENGE;
            response.Data.Add(RealmData.RD_AUTH_ERROR, 0);
            response.Data.Add(RealmData.RD_AUTH_HASH, temp.getBytes());
            response.Data.Add(RealmData.RD_AUTH_SALT, salt);
            response.Data.Add(RealmData.RD_AUTH_N, N);
            return response;
        }
开发者ID:bobobear,项目名称:wowmachinimastudio,代码行数:30,代码来源:RealmServer.cs


示例18: Index

 public ActionResult Index()
 {
     Init();
     ViewData["timestamp"] = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
     Random random = new Random();
     ViewData["nonceStr"] = new string(
         Enumerable.Repeat("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 16)
                   .Select(s => s[random.Next(s.Length)])
                   .ToArray()); ;
     string weaTokenFetchUrl = string.Format(@"https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token={0}", weAccessToken.AccessToken);
     if (jsTicket==null||!jsTicket.IsValid)
     {
         using (var webClient = new WebClient())
         {
             string response = webClient.DownloadString(weaTokenFetchUrl);
             jsTicket = JsonConvert.DeserializeObject<WEAJsApiTicket>(response);
         }
     }
     byte[] hashData = Encoding.Default.GetBytes(string.Format("jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}", jsTicket.Ticket, ViewData["nonceStr"].ToString(), ViewData["timestamp"].ToString(), Request.Url.AbsoluteUri));
     SHA1 sha = new SHA1CryptoServiceProvider();
     byte[] hashResult = sha.ComputeHash(hashData);
     string signature = BitConverter.ToString(hashResult).Replace("-", string.Empty).ToLower();
     ViewData["signature"] = signature;
     return View();
 }
开发者ID:TheBlackPear,项目名称:wechatPhotoUpload,代码行数:25,代码来源:HomeController.cs


示例19: EncodePassword

 public static string EncodePassword(string password)
 {
     using (SHA1CryptoServiceProvider Sha = new SHA1CryptoServiceProvider())
     {
         return Convert.ToBase64String(Sha.ComputeHash(Encoding.ASCII.GetBytes(password)));
     }
 }
开发者ID:arduosoft,项目名称:wlog,代码行数:7,代码来源:UserHelper.cs


示例20: CalculateSHA1

 // Slightly modified stackoverflow code for sha1
 public static string CalculateSHA1(string text)
 {
     Encoding enc = Encoding.GetEncoding(1252);
     byte[] buffer = enc.GetBytes(text);
     SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
     return BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
 }
开发者ID:thgilfodrol,项目名称:Unofficial-Shotbow-GunGame-Statistics-Collector,代码行数:8,代码来源:Program.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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