首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >System.Security.Cryptography对Windows.Security.Cryptography

System.Security.Cryptography对Windows.Security.Cryptography
EN

Stack Overflow用户
提问于 2012-10-08 22:37:49
回答 2查看 13.2K关注 0票数 14

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

我目前正在将该应用程序作为一个现代UI (Metro)应用程序移植到Windows 8。它进行得很好,除了当我试图导入我的密钥派生代码(它使用用户的密码并从中派生一个256位键),VisualStudioUltimal2013表示它不识别using System.Security.Cryptography

在查看了Windows8Developer网站之后,我发现一个新的类Windows.Security.Cryptography是可用的,但是它似乎也没有被Visual所识别。

所以,既然你有了背景,我有几个问题:

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

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

代码语言:javascript
运行
复制
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;
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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

票数 4
EN

Stack Overflow用户

发布于 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

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12790459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档