c# - Windows Phone 8 上的 X509Certificate2 到 X509Certificate

标签 c# windows-phone-7 encryption windows-phone-8 windows-phone

我需要让以下代码在 WP8 上运行,问题是 WP8 上没有 X509Certificate2 类,我尝试过使用 bouncy caSTLe api,但我还没有真正弄明白。

有没有办法让这段代码在 WP8 上工作?

    private string InitAuth(X509Certificate2 certificate, string systemId, string username, string password)
    { 
        byte[] plainBytes = Encoding.UTF8.GetBytes(password);
        var cipherB64 = string.Empty;
        using (var rsa = (RSACryptoServiceProvider)certificate.PublicKey.Key)
            cipherB64 = systemId + "^" + username + "^" + Convert.ToBase64String(rsa.Encrypt(plainBytes, true));

        return cipherB64;
    }

最佳答案

您不能解决 X509Certificate2 的可用性问题吗?

private string InitAuth(X509Certificate certificate, string systemId, string username, string password)
    { 
        byte[] plainBytes = Encoding.UTF8.GetBytes(password);
        var cipherB64 = string.Empty;

        //Create a new instance of RSACryptoServiceProvider.
        RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

        //Create a new instance of RSAParameters.
        RSAParameters RSAKeyInfo = new RSAParameters();

        //Set RSAKeyInfo to the public key values. 
        RSAKeyInfo.Modulus = certificate.getPublicKey();
        RSAKeyInfo.Exponent = new byte[3] {1,0,1};;

        //Import key parameters into RSA.
        RSA.ImportParameters(RSAKeyInfo);

        using (RSA)
            cipherB64 = systemId + "^" + username + "^" + Convert.ToBase64String(RSA.Encrypt(plainBytes, true));

        return cipherB64;
    }

披露:我没有尝试上面的代码,因为我目前没有可供我使用的 C# 运行时环境。

关于c# - Windows Phone 8 上的 X509Certificate2 到 X509Certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16187307/

相关文章:

c# - 当只有我知道它的后代时,在 XPATH 中获取一个值?

c# - 导入MySQL时格式化数据表日期列

c# - 如果标签在 GroupBox 中,为什么标签控件不会在 foreach 循环中被命中?

windows-phone-7 - System.Windows.Navigation.NavigationService.Navigate 抛出无效操作异常

javascript - 动态加密的 Paypal 按钮?

c# - 一段时间后 NLog 停止运行

windows-phone-7 - Windows Phone 8 SDK Xde 模拟器运行速度非常慢并且崩溃

c# - 有没有办法以编程方式检查飞行模式状态?

Android中的C#密码编码

ios - 解码 SHA256 Objective C