本文整理汇总了C#中Rfc2898DeriveBytes.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Rfc2898DeriveBytes.Reset方法的具体用法?C# Rfc2898DeriveBytes.Reset怎么用?C# Rfc2898DeriveBytes.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rfc2898DeriveBytes
的用法示例。
在下文中一共展示了Rfc2898DeriveBytes.Reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildRijndaelKeys
// RandomNumber
// PublicKey
// PublicKey2Str
// Variables
// BuildAESKeys
// EncryptWithAES
// DecryptWithAES
// NOTE: Rijndael is NOT supported in WP8. If you want to use the Rijndael on
// other platforms, simply add a compiler directive of "UseRijndael", or
// comment out the if / endif lines
#endregion Other
#if (UseRijndael)
// BuildRijndaelKeys
// EncryptWithRijndael
// DecryptWithRijndael
/// <summary>
/// builds keys for the crypto
/// </summary>
/// <param name="RCrypto"></param>
/// <param name="key">the key to build with</param>
/// <param name="keyStr">the key string to build with</param>
private static void BuildRijndaelKeys(RijndaelManaged RCrypto, string keyStr, byte[] key)
{
// set block and key size
RCrypto.BlockSize = RCrypto.LegalBlockSizes[0].MaxSize;
RCrypto.KeySize = RCrypto.LegalKeySizes[0].MaxSize;
/*
What the key derivation function (Rfc2898DeriveBytes) does is repeatedly hash the user password along with a salt. This has multiple benefits:
1) you can use arbitrarily sized passwords – AES only supports specific key sizes.
2) the addition of the salt means that you can use the same passphrase to generate multiple different.
This is important for key separation; reusing keys in different contexts is one of the most common ways cryptographic systems are broken.
The beauty of this is that every time you encrypt plain text P1 with the derived key, you will get a different cipher text out the other side.
But those different cipher texts can all be decrypted with the same key.
*/
Rfc2898DeriveBytes KeyDerivationFunction = new Rfc2898DeriveBytes(keyStr, key);
// derive our key, and IV (Rijndael)
byte[] keyBytes = KeyDerivationFunction.GetBytes(RCrypto.KeySize / 8);
KeyDerivationFunction.Reset();
byte[] ivBytes = KeyDerivationFunction.GetBytes(RCrypto.BlockSize / 8);
// populate keys in crypto
RCrypto.Key = keyBytes;
RCrypto.IV = ivBytes;
RCrypto.Mode = CipherMode.CBC;
RCrypto.Padding = PaddingMode.PKCS7;
}