gpt4 book ai didi

c# - Windows Phone 8 上的 X509Certificate2 到 X509Certificate

转载 作者:太空狗 更新时间:2023-10-29 21:58:22 26 4
gpt4 key购买 nike

我需要让以下代码在 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# 运行时环境。

关于c# - Windows Phone 8 上的 X509Certificate2 到 X509Certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16187307/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com