我需要使以下代码在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#运行时环境。
关于c# - Windows Phone 8上的X509Certificate2到X509Certificate,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16187307/