Windows Phone 8上的X509Certificate2到X509Certificate

jjd*_*v80 6 c# encryption windows-phone-7 windows-phone windows-phone-8

我需要在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;
    }
Run Code Online (Sandbox Code Playgroud)

lik*_*eit 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;
    }
Run Code Online (Sandbox Code Playgroud)

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