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 に答える