0

我有以下内容:

interface IDefectRepository { /* ... */ }
class MyDefectRepository : IDefectRepository
{
    public MyDefectRepository(string url, string userName, string password)
    {
        // ...
    }

    // ...
}

我正在使用 <parameters> 从 Web.config 传递构造函数参数。有什么方法可以将加密的密码存储在 Web.config 文件中?其他建议?

4

2 回答 2

1

尝试继承MyDefectRepositoryWithEncryptedPasswordsMyDefectRepository. 在MyDefectRepositoryWithEncryptedPasswords构造函数中解密密码并将其传递给MyDefectRepository构造函数,如下所示:

class MyDefectRepositoryWithEncryptedPasswords : MyDefectRepository
{
    public MyDefectRepositoryWithEncryptedPasswords(string url, string userName, string encryptedPassword)
        : base(url, userName, Decrypt(encryptedPassword))
    {
    }

    public static string Decrypt(string encrypted)
    {
        // Do whatever...
    }
}

无论如何,我认为您不应该使用双向加密方法存储加密密码。您应该使用某种散列(加密类型)并比较散列。这将需要更改您的构造函数以接收不是密码,而是它的哈希值。

于 2009-03-11T11:17:46.960 回答
1

You could inject the password via a ISubDependencyResolver (sample1, sample2) which would get the password from an encrypted section in your web.config.

于 2009-03-11T23:54:14.303 回答