【发布时间】:2012-04-01 19:20:27
【问题描述】:
我有一个函数GetPassword,它返回一个SecureString 类型。
当我将此安全字符串传递给 Rfc2898DeriveBytes 以生成密钥时,Visual Studio 显示错误。我有限的知识告诉我这是因为Rfc2898DeriveBytes 只接受一个字符串而不接受一个安全字符串。有解决办法吗?
//read the password from terminal
Console.Write("Insert password");
securePwd = myCryptography.GetPassword();
//dont know why the salt is initialized like this
byte[] salt = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45 };
try
{ //PBKDF2 standard
Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(securePwd, salt, iterationsPwd);
【问题讨论】:
-
...哦,你,我不知道为什么盐是这样的:D
-
我现在在做什么,是我使用securePwd.ToString 问题是它使使用secureString的整个过程毫无价值:D
-
就是,以
//read the password from terminal开头的 -
ToString()返回SecureString的内容?你确定吗?文档不是这么说的。
标签: c# cryptography securestring pbkdf2