Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows Phone 8上的X509Certificate2到X509Certificate_C#_Windows Phone 7_Encryption_Windows Phone 8_Windows Phone - Fatal编程技术网

C# Windows Phone 8上的X509Certificate2到X509Certificate

C# Windows Phone 8上的X509Certificate2到X509Certificate,c#,windows-phone-7,encryption,windows-phone-8,windows-phone,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 = Encodi

我需要让下面的代码在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#运行时环境供我使用。

@MaryJ。你看了吗?没有,对不起,我没有时间看。请回答这个问题@likeitlikeit