繁体   English   中英

Windows Phone 8上的X509Certificate2到X509Certificate

[英]X509Certificate2 to X509Certificate on 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;
    }

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM