我是一个新的Windows 8开发人员,我有一些代码是为Linux设计的,但只要安装了GTK#,也可以在Windows上运行。
我目前正在将该应用程序作为一个现代UI (Metro)应用程序移植到Windows 8。它进行得很好,除了当我试图导入我的密钥派生代码(它使用用户的密码并从中派生一个256位键),VisualStudioUltimal2013表示它不识别using System.Security.Cryptography
。
在查看了Windows8Developer网站之后,我发现一个新的类Windows.Security.Cryptography
是可用的,但是它似乎也没有被Visual所识别。
所以,既然你有了背景,我有几个问题:
为了澄清我想做什么,我的关键派生代码张贴在下面:
public class GetKey
{
// constructor
public GetKey (bool use=true, string password="none")
{ if (use == true)
{
this.genSalt();
byte[] salt = this.salt;
Rfc2898DeriveBytes pwdKey = new Rfc2898DeriveBytes(password, salt, 4000);
this.key = pwdKey.GetBytes(32);
this.iv = pwdKey.GetBytes(16);
}
}
// properties
private byte[] key;
private byte[] iv;
private byte[] salt;
// methods
public void retrieveKey(string password)
{
try
{
byte[] salt = this.salt;
Rfc2898DeriveBytes pwdKey = new Rfc2898DeriveBytes(password, salt, 4000);
this.key = pwdKey.GetBytes(32);
this.iv = pwdKey.GetBytes(16);
}
catch (Exception e)
{
GenericDialog win = new GenericDialog("Unknown Error: " + e.Message, "Error Notice", "Unknown Error");
win.Show();
}
}
public void genSalt()
{
string sSalt = UtilityClass.randString(16);
byte[] salt = UtilityClass.ToByteArray(sSalt);
this.salt = salt;
}
public byte[] returnKey()
{
return this.key;
}
public byte[] returnIv()
{
return this.iv;
}
public byte[] returnSalt()
{
return this.salt;
}
public bool setSalt(string salt)
{
try
{
this.salt = Convert.FromBase64String(salt);
}
catch
{
GenericDialog win = new GenericDialog("Decryption failed because the salt was invalid.", "Error Notice", "Invalid Salt");
win.Show();
return false;
}
return true;
}
}
发布于 2012-11-11 17:47:57
Windows.Security.Cryptography和它的子名称空间可能是要走的路。
有关使用几种不同算法派生关键材料的方法,请参见http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.core.cryptographicengine.derivekeymaterial.aspx。
发布于 2013-01-25 20:08:31
1) System.Security.Cryptography在Windows应用程序中不可用,因此您必须使用Windows.Security.Cryptography。有关使用.NET可移植库重用不同目标框架类库的详细说明,请参阅下面的链接。如果需要,您总是可以使用您最喜欢的IoC容器注入一个抽象。
http://www.hanselman.com/blog/HiddenGemsInVisualStudio11BetaNETPortableClassLibraries.aspx
2)我没有看到Rfc2898DeriveBytes在Windows.Security.Cryptography或类似的东西中的实现。见下文。
http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.core.symmetricalgorithmnames.aspx
https://stackoverflow.com/questions/12790459
复制相似问题