當前位置: 首頁>>代碼示例>>C#>>正文


C# Rfc2898DeriveBytes.Dispose方法代碼示例

本文整理匯總了C#中System.Security.Cryptography.Rfc2898DeriveBytes.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# Rfc2898DeriveBytes.Dispose方法的具體用法?C# Rfc2898DeriveBytes.Dispose怎麽用?C# Rfc2898DeriveBytes.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Security.Cryptography.Rfc2898DeriveBytes的用法示例。


在下文中一共展示了Rfc2898DeriveBytes.Dispose方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AESEncryptData

        private static byte[] AESEncryptData(byte[] Data, byte[] key, byte[] IVSeed)
        {
            byte[] retByte;

            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes rfcDBGen = new Rfc2898DeriveBytes(key, IVSeed, 128);
                encryptor.IV = rfcDBGen.GetBytes(16);
                encryptor.Key = rfcDBGen.GetBytes(32);
                rfcDBGen.Dispose();
                using(MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(Data, 0, Data.Length);
                        cs.Close();
                    }
                    retByte = ms.ToArray();
                }
            }

            return retByte;
        }
開發者ID:TCSolutions,項目名稱:Event-Driven-Network-Libary,代碼行數:23,代碼來源:AESPacketEncryptor.cs

示例2: Hi

		/// <summary>
		/// Computes the "Hi()"-formula which is part of the client's response
		/// to the server challenge.
		/// </summary>
		/// <param name="password">The supplied password to use.</param>
		/// <param name="salt">The salt received from the server.</param>
		/// <param name="count">The iteration count.</param>
		/// <returns>An array of bytes containing the result of the computation of the
		/// "Hi()"-formula.</returns>
		/// <remarks>
		/// Hi is, essentially, PBKDF2 with HMAC as the pseudorandom function (PRF) and with
		/// dkLen == output length of HMAC() == output length of H(). (Refer to RFC 5802, p.6)
		/// </remarks>
		private byte[] Hi(string password, string salt, int count) {
			// The salt is sent by the server as a base64-encoded string.
			byte[] saltBytes = Convert.FromBase64String(salt);
			// Annoyingly, Rfc2898DeriveBytes only implements IDisposable in .NET 4 and upwards.
			var db = new Rfc2898DeriveBytes(password, saltBytes, count);
			try {
				// Generate 20 key bytes, which is the size of the hash result of SHA-1.
				return db.GetBytes(20);
			} finally {
#if !NET35
				if(db != null)
					db.Dispose();
#endif
			}
		}
開發者ID:abhibecb,項目名稱:S22.Imap,代碼行數:28,代碼來源:SaslScramSha1.cs

示例3: DeepLinkHelper

        static DeepLinkHelper()
        {
            const string Password = "aGD4d&%SS1&gFd&F!";
            const string SaltString = "[email protected]%f&!hg8asH2J7";

            var salt = Encoding.UTF8.GetBytes(SaltString);

            using (var encryptionAlgorithm = new AesManaged())
            {
                BlockSize = encryptionAlgorithm.LegalBlockSizes[0].MaxSize;
                KeySize = encryptionAlgorithm.LegalKeySizes[0].MaxSize;
            }

            Rfc2898DeriveBytes keyGenerator = null;

            try
            {
                keyGenerator = new Rfc2898DeriveBytes(Password, salt);
                Key = keyGenerator.GetBytes(KeySize / 8);
                InitializationVector = keyGenerator.GetBytes(BlockSize / 8);
            }
            finally
            {
#if !SILVERLIGHT
                if (keyGenerator != null)
                {
                    keyGenerator.Dispose();
                }
#endif
            }
        }
開發者ID:mparsin,項目名稱:Elements,代碼行數:31,代碼來源:DeepLinkHelper.cs

示例4: Hi

        private byte[] Hi(string password, string salt, int count)
        {
            byte[] saltBytes = Convert.FromBase64String(salt);

            var db = new Rfc2898DeriveBytes(password, saltBytes, count);
            try
            {
                return db.GetBytes(20);
            }
            finally
            {
            #if !NET35
                if (db != null)
                {
                    db.Dispose();
                }
            #endif
            }
        }
開發者ID:BoyarinO,項目名稱:EmailClient,代碼行數:19,代碼來源:SaslScramSha1.cs

示例5: hashPassword

    //This area contains all static methods.
    //This method uses the rfc2898 hash class to hash the users password.
    public static Client hashPassword(Client user)
    {
        //tries to perform hash and catches null string
        try
        {
            const int SALT_SIZE = 16;
            byte[] saltInBytes = new byte[SALT_SIZE];

            //Creates a random salt.
            new RNGCryptoServiceProvider().GetBytes(saltInBytes);
            user.Salt = saltInBytes;

            //Generates hash with 16 byte salt, and 10000 iterations
            Rfc2898DeriveBytes hash1 = new Rfc2898DeriveBytes(user.password, saltInBytes, ITERATIONS);

            //Gets the hashed object.
            byte[] hash = hash1.GetBytes(20);

            user.Password = Convert.ToBase64String(hash);

            hash1.Dispose();
            //Returns the user with hashed password and salt assigned.
            return user;

            #region Zach's MD5 Hashing Algorithm
            ////holder for return text
            //string returnText;
            ////converts input text into bytes
            //byte[] textbytes = System.Text.Encoding.Default.GetBytes(password);
            ////creates hash object
            //System.Security.Cryptography.MD5 hash = System.Security.Cryptography.MD5.Create();
            ////gets hashed text as a string
            //returnText = System.Text.Encoding.Default.GetString(hash.ComputeHash(textbytes));
            ////cleans up
            //hash.Dispose();
            ////returns holder for hashed text
            //return returnText; 
            #endregion
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            return null;
        }
    }
開發者ID:patdGitHub,項目名稱:Real-Time-Server-Connected-Code-Editor,代碼行數:47,代碼來源:Client.cs

示例6: PBKDF2

 /// <summary>
 /// Computes the PBKDF2-SHA1 hash of a password.
 /// </summary>
 /// <param name="password">The password to hash.</param>
 /// <param name="salt">The salt.</param>
 /// <param name="iterations">The PBKDF2 iteration count.</param>
 /// <param name="outputBytes">The length of the hash to generate, in bytes.</param>
 /// <returns>A hash of the password.</returns>
 private static byte[] PBKDF2(string password, byte[] salt, int iterations, int outputBytes)
 {
     Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(password, salt);
     pbkdf2.IterationCount = iterations;
     byte[] rtn = pbkdf2.GetBytes(outputBytes);
     pbkdf2.Dispose();
     return rtn;
 }
開發者ID:qsqurrl,項目名稱:TCMAPWCFServer,代碼行數:16,代碼來源:Password.cs


注:本文中的System.Security.Cryptography.Rfc2898DeriveBytes.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。