1
votes

Hi i am trying o generate my public key for my RSA 4096 encryption in my windows phone 8 ecryption app

i am using this method:

RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(4096); var pub_key = rsaProvider.ExportParameters(false); // export public key

and now i am trying to convert the pub_key to a pem format so i can send it to the server i am doing the below step

Byte[] bpkey = Combine(pub_key.Modulus, pub_key.Exponent);

i am combining the byte array into one using " RSA public key = modulus + exponent "

string pkey = "----BEGIN PUBLIC KEY----\n" + Convert.ToBase64(bpkey)+ "\n----END PUBLIC KEY----";

but i am getting that the pkey is an invalid pem format when i send it to the server!!!

any idea how to it correctly or how to fix the error.

2

2 Answers

1
votes

just like i say if your server DeEncrypt string use Java language . you can't use RSACryptoServiceProvider encrypt string in windows phone client.

.Net platform SDK provides RSA encryption due plus random numbers, so it must also decrypt the. Net platform for decryption. If you keep such a cross-platform java platform decryption will be a problem.

you can try this way . use bigintege convert string http://www.codeproject.com/csharp/biginteger.asp

will be fine

1
votes

Actually it's because there's a difference in signing between Java and .NET (little endian vs big endian). Just reverse the byte arrays and you should be good to go. Also check out:

http://scrypt.codeplex.com