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


C# Rfc2898DeriveBytes.Reset方法代码示例

本文整理汇总了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;
    }
开发者ID:rocketgames,项目名称:Extension-Methods-for-Unity,代码行数:55,代码来源:CryptoExtensions.cs


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