相关疑难解决方法(0)

你最喜欢的C#扩展方法是什么?(codeplex.com/extensionoverflow)

让我们列出你发布优秀和最喜欢的扩展方法的答案.

要求是必须发布完整代码并提供示例和如何使用它的说明.

基于对该主题的高度关注,我在Codeplex上设置了一个名为extensionoverflow的开源项目.

请标记您的答案并接受将代码放入Codeplex项目中.

请发布完整的源代码而不是链接.

Codeplex新闻:

24.08.2010 Codeplex页面现在在这里:http://extensionoverflow.codeplex.com/

11.11.2008 XmlSerialize/XmlDeserialize现在已实现并且已经过单元测试.

11.11.2008仍有更多开发人员的空间.;-) 现在加入!

11.11.2008第三个贡献者加入了ExtensionOverflow,欢迎来到BKristensen

11.11.2008 FormatWith现在已实现且已经过单元测试.

09.11.2008第二个贡献者加入了ExtensionOverflow.欢迎来到chakrit.

09.11.2008我们需要更多开发人员.;-)

09.11.2008 ThrowIfArgumentIsNull现在在Codeplex上实现单元测试.

.net c# extension-methods open-source

478
推荐指数
57
解决办法
12万
查看次数

为什么密码错误导致"填充无效且无法删除"?

我需要一些简单的字符串加密,所以我写了下面的代码(从这里有很多"灵感" ):

    // create and initialize a crypto algorithm
    private static SymmetricAlgorithm getAlgorithm(string password) {
        SymmetricAlgorithm algorithm = Rijndael.Create();
        Rfc2898DeriveBytes rdb = new Rfc2898DeriveBytes(
            password, new byte[] {
            0x53,0x6f,0x64,0x69,0x75,0x6d,0x20,             // salty goodness
            0x43,0x68,0x6c,0x6f,0x72,0x69,0x64,0x65
        }
        );
        algorithm.Padding = PaddingMode.ISO10126;
        algorithm.Key = rdb.GetBytes(32);
        algorithm.IV = rdb.GetBytes(16);
        return algorithm;
    }

    /* 
     * encryptString
     * provides simple encryption of a string, with a given password
     */
    public static string encryptString(string clearText, string password) {
        SymmetricAlgorithm algorithm = getAlgorithm(password);
        byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText); …
Run Code Online (Sandbox Code Playgroud)

.net c# encryption exception

40
推荐指数
3
解决办法
7万
查看次数