6

我需要让以下代码在 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;
    }
4

1 回答 1

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# 运行时环境可供我使用。

于 2013-05-02T18:06:39.443 回答