X509Certificate2 to X509Certificate on Windows Phone 8

I need to make the following code for WP8, the problem is that on WP8 there is no X509Certificate2 class, I tried to use bouncy castle apis, but I could not figure it out.

Is there a way to get this code to work on 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; } 
+6
source share
1 answer

Can't you just get around the availability of 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; } 

DISCLOSURE: I have not tried the code above because I currently do not have a C # runtime.

+1
source

Source: https://habr.com/ru/post/943514/


All Articles