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


C# Cryptography.SHA1CryptoServiceProvider类代码示例

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


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

示例1: GetSha1Hash

 public static string GetSha1Hash(this string value)
 {
     var encoding = new UTF8Encoding();
     var hash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     var hashed = hash.ComputeHash(encoding.GetBytes(value));
     return encoding.GetString(hashed);
 }
开发者ID:MrHayato,项目名称:PhotoCache,代码行数:7,代码来源:StringExtensions.cs

示例2: GetSHA1Hash

        public static string GetSHA1Hash(string pathName)
        {
            string strResult = "";
            string strHashData = "";

            byte[] arrbytHashValue;
            System.IO.FileStream oFileStream = null;

            System.Security.Cryptography.SHA1CryptoServiceProvider oSHA1Hasher =
                       new System.Security.Cryptography.SHA1CryptoServiceProvider();

            try
            {
                oFileStream = GetFileStream(pathName);
                arrbytHashValue = oSHA1Hasher.ComputeHash(oFileStream);
                oFileStream.Close();

                strHashData = System.BitConverter.ToString(arrbytHashValue);
                strHashData = strHashData.Replace("-", "");
                strResult = strHashData;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error!",
                         System.Windows.Forms.MessageBoxButtons.OK,
                         System.Windows.Forms.MessageBoxIcon.Error,
                         System.Windows.Forms.MessageBoxDefaultButton.Button1);
            }

            return (strResult);
        }
开发者ID:VISTALL,项目名称:game-updater,代码行数:31,代码来源:DTHasher.cs

示例3: init

 public void init()
 {
     //    signature=java.security.Signature.getInstance("SHA1withRSA");
     //    keyFactory=KeyFactory.getInstance("RSA");
     sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     cs = new System.Security.Cryptography.CryptoStream(System.IO.Stream.Null, sha1, System.Security.Cryptography.CryptoStreamMode.Write);
 }
开发者ID:salimci,项目名称:Legacy-Remote-Recorder,代码行数:7,代码来源:SignatureRSA.cs

示例4: GetSHA1Hash

        public static string GetSHA1Hash(string pathName)
        {
            string strResult = "";
            string strHashData = "";

            byte[] arrbytHashValue;
            System.IO.FileStream oFileStream = null;

            System.Security.Cryptography.SHA1CryptoServiceProvider oSHA1Hasher =
                       new System.Security.Cryptography.SHA1CryptoServiceProvider();

            try
            {
                oFileStream = GetFileStream(pathName);
                arrbytHashValue = oSHA1Hasher.ComputeHash(oFileStream);
                oFileStream.Close();

                strHashData = System.BitConverter.ToString(arrbytHashValue);
                strHashData = strHashData.Replace("-", "");
                strResult = strHashData;
            }
            catch (System.Exception)
            {
            }

            return (strResult);
        }
开发者ID:atom0s,项目名称:Campah,代码行数:27,代码来源:Updater.xaml.cs

示例5: Generate

        public static string Generate()
        {
            // Generate random
            var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
            var entropy = new byte[bytes - 4];
            try {
                rnd.GetBytes(entropy);
            } finally {
                rnd.Dispose();
            }

            // Hash
            var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] hash;
            try {
                hash = sha.ComputeHash(entropy);
            } finally {
                sha.Dispose();
            }

            // Compute output
            var raw = new byte[bytes];
            Array.Copy(entropy, 0, raw, 0, bytes - 4);
            Array.Copy(hash, 0, raw, bytes - 4, 4);

            // Convert to Base64
            return Convert.ToBase64String(raw).Replace('+', '!').Replace('/', '~');
        }
开发者ID:invertedtomato,项目名称:Amos2,代码行数:28,代码来源:Tokens.cs

示例6: GetFeatureOfHuman

        public static Guid GetFeatureOfHuman(byte[] humanDescriptionBytes)
        {
            byte[] hashedBytes = new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(humanDescriptionBytes);

            Array.Resize(ref hashedBytes, 16);

            return new Guid(hashedBytes);
        }
开发者ID:ViniciusConsultor,项目名称:ecustomsgs1,代码行数:8,代码来源:XRayController.cs

示例7: GetCryptographyString

        private static string GetCryptographyString(string strSource)
        {
            System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] bytes = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(strSource));
            string result = BitConverter.ToString(bytes, 4, 8).Replace("-","");

            return result;
        }
开发者ID:wangsying,项目名称:EasySite,代码行数:8,代码来源:CurrentUser.cs

示例8: createHash

        /// <summary>
        /// Retorna el hash SHA1 de la cadena de texto que recibe como parámetro.
        /// </summary>
        /// <param name="unHashed">Cadena de texto a encriptar.</param>
        /// <returns>Hash de la cadena de texto. SHA1.</returns>
        public static string createHash(string unHashed)
        {
            System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] data = System.Text.Encoding.ASCII.GetBytes(unHashed);
            data = x.ComputeHash(data);

            return Convert.ToBase64String(data);
        }
开发者ID:jlsarmientoh,项目名称:EstacionDB,代码行数:13,代码来源:Security.cs

示例9: GenerateAuthorizationToken

 private static string GenerateAuthorizationToken(string passTypeIdentifier, string serialNumber)
 {
     using (System.Security.Cryptography.SHA1CryptoServiceProvider hasher = new System.Security.Cryptography.SHA1CryptoServiceProvider())
     {
         byte[] data = Encoding.UTF8.GetBytes(passTypeIdentifier.ToLower() + serialNumber.ToLower() + mAuthorizationKey);
         return System.BitConverter.ToString(hasher.ComputeHash(data)).Replace("-", string.Empty).ToLower();
     }
 }
开发者ID:joe-keane,项目名称:dotnet-passbook,代码行数:8,代码来源:PassbookBaseController.cs

示例10: Hash

 private static string Hash(string toHash)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] data = System.Text.Encoding.ASCII.GetBytes(toHash);
     data = x.ComputeHash(data);
     string o = BitConverter.ToString(data).Replace("-", "").ToUpper();
     return o;
 }
开发者ID:tylermenezes,项目名称:Rfid-Credential-Provider,代码行数:8,代码来源:Program.cs

示例11: Main

        public static string root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // string root points to MyDocuments

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "-v")
                {
                    Console.WriteLine("asdasd");
                    if (File.Exists(prefs + "/gkey"))
                    {
                            using (System.IO.StreamReader sr = new System.IO.StreamReader(prefs + "/gkey"))
                            {
                                string data = sr.ReadToEnd();
                                string[] f = data.Split('\n');
                                sr.Dispose();
                                if (f[0] == "accepted")
                                {
                                    string HASH = f[1].ToString();
                                    using (System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
                                    {
                                        string hashsum = string.Empty;                  // Empty storage allocator
                                        byte[] da = sha1.ComputeHash(Encoding.Unicode.GetBytes(prefs + "/gkey"));       // byte array
                                        foreach (byte by in data)
                                        {
                                            hashsum += String.Format("{0,2:X2}", by);        // :-)
                                        }

                                        if (hashsum.ToString() != HASH.ToString())
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.Write("SECURITY COMPROMISED!\n\nSHA1 HASH MODIFIED!\nRECORD DOES NOT MATCH G_KEY!\n\nCACHE WILL BE DELETED FOR SECURITY.");
                                            Console.Read();

                                        }

                                        else ;
                                        sha1.Dispose();

                                        try
                                        {
                                            Directory.Delete(prefs);
                                        }

                                        catch { ; }
                                    }
                                }

                            }

                    }
                }

            }

            else
            {
                Console.Write("This is not a standalone application.");
            }
        }
开发者ID:kryptonX,项目名称:Scale,代码行数:64,代码来源:Program.cs

示例12: EncryptToSHA1

 public string EncryptToSHA1(string str)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] str1 = System.Text.Encoding.UTF8.GetBytes(str);
     byte[] str2 = sha1.ComputeHash(str1);
     sha1.Clear();
     (sha1 as IDisposable).Dispose();
     return Convert.ToBase64String(str2);
 }
开发者ID:iCnG,项目名称:myGitHub,代码行数:9,代码来源:Default.aspx.cs

示例13: GetSHA1

 public static string GetSHA1(string pwdata_s)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider osha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     ASCIIEncoding enc = new ASCIIEncoding();
     byte[] pwdata_b = enc.GetBytes(pwdata_s);//password(string) to byte[]
     byte[] pwsha1_b = osha1.ComputeHash(pwdata_b);//ToHash
     string pwsha1_s = BitConverter.ToString(pwsha1_b).Replace("-", "");//hash to string
     return pwsha1_s;
 }
开发者ID:RhodesZ,项目名称:Seekme,代码行数:9,代码来源:Login.cs

示例14: sha1

 public string sha1(string input)
 {
     byte[] hash;
     using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
         hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(input));
     var sb = new StringBuilder();
     foreach (byte b in hash) sb.AppendFormat("{0:x2}", b);
     return sb.ToString();
 }
开发者ID:alexeykuzmin7,项目名称:Diplom_project,代码行数:9,代码来源:Form7.cs

示例15: HashString

 public static string HashString(string Value)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
     data = x.ComputeHash(data);
     string ret = "";
     for (int i = 0; i < data.Length; i++)
         ret += data[i].ToString("x2").ToLower();
     return ret;
 }
开发者ID:pederjohnsen,项目名称:Nimbus,代码行数:10,代码来源:Security.cs


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