Hello,
RSACryptoServiceProvider class provides 3 different ways to import and export Crypto keys.
- To and from XML
- To and from BLOB (Binary)
- To and from RSAParamters
I have worked fine with XML implementaion, I Export and save XML based key pair and use it later when I need.
For some reason I want to use Binary implementation,
The simplest solution seems that I use following:
RSACryptoServiceProvider
rsaCryptoServiceProvidesCipher;rsaCryptoServiceProvidesCipher = new RSACryptoServiceProvider(2048);
byte
[] key = this.rsaCryptoServiceProvidesCipher.ExportCspBlob(true);now I hardcode this key in the assembly and use it later. Now the problem is what if someone decompiles the assembly and knows the key in form of byte[] key = new byte[] {21,132,143,23,....};
I use Obfuscator to obfuscate the assembly and then give it to our clients. Many obfuscators provide string encryption and not the code lines like in my scenerio.
The way I want to save my key is that I want to convert this Binary key to string and then string back to binary for use. In this way I'll put obfuscation work to the tool and my work is done.
I used ASCII, Unicode, UTF8, UTF7 infact all encodings to save and retrive this key back and assing to to Cipher but I get Exception Bad Data or Bad key. If i dont do any conversion to string wheter assign the bytes[] direct to the Cipher it works fine.
Can anybody point how and in which format I save this key into string Or there is any otherway than doing this
I tried to be descriptive and clear while answering my question if you need more information, I'm here.
Thank you all in advance.
Best Regards,

Exporting and Importing RSA Keys in Binary!!!
BradN
Ahhhhhhhh, Caught it
string
strKey = Convert.ToBase64String(key); byte[] newKey = Convert.FromBase64String(strKey);Love it