gpt4 book ai didi

c# - System.Security.Cryptography 与 Windows.Security.Cryptography

转载 作者:可可西里 更新时间:2023-11-01 08:22:55 25 4
gpt4 key购买 nike

我是一名新的 Windows 8 开发人员,我有一些代码是为 Linux 设计的,但只要安装了 GTK# 也可以在 Windows 上运行。

我目前正在将该应用程序作为现代 UI (Metro) 应用程序移植到 Windows 8。一切顺利,除了,当我尝试导入我的 key 派生代码(获取用户密码并从中派生 key 256 位 key )时,Visual Studio Ultimate 2013 指示它无法识别 using System.安全.密码学

在查看 Windows 8 开发者网站后,我发现有一个新类 Windows.Security.Cryptography 可用,但是,Visual Studio 似乎也无法识别它。

那么,既然你已经有了背景,我有几个问题:

  1. System.Security.Cryptography 在 Windows 8 中可用吗?如果可以,是否支持 RT 版本?如何让 Visual Studio 识别它?
  2. Windows.System.Security 有何不同,是否有与 Rfc2898DeriveBytes 兼容的类/方法?兼容,我的意思是给定相同的密码和 salt 是否有办法获得相同的 key 作为结果。

为了澄清我想做什么,我的 key 派生代码贴在下面:

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;
}
}

最佳答案

1) System.Security.Cryptography 在 Windows 应用商店应用程序中不可用,因此您必须使用 Windows.Security.Cryptography。有关使用 .NET 可移植库为不同目标框架重用类库的详细解释,请参见下面的链接。如果需要,您始终可以使用您最喜欢的 IoC 容器注入(inject)抽象。

http://www.hanselman.com/blog/HiddenGemsInVisualStudio11BetaNETPortableClassLibraries.aspx

2) 我没有在 Windows.Security.Cryptography 或类似的东西中看到 Rfc2898DeriveBytes 的实现。见下文。

http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.core.symmetricalgorithmnames.aspx

关于c# - System.Security.Cryptography 与 Windows.Security.Cryptography,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12790459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com