【问题标题】:X509Certificate2 to X509Certificate on Windows Phone 8Windows Phone 8 上的 X509Certificate2 到 X509Certificate
【发布时间】:2013-04-24 08:39:20
【问题描述】:

我需要让以下代码在 WP8 上运行,问题是 WP8 上没有 X509Certificate2 类,我尝试过使用充气城堡 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;
    }

【问题讨论】:

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


    【解决方案1】:

    您不能解决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# 运行时环境。

    【讨论】:

    猜你喜欢
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多