Im creating xml string from my RSA key:
var keyXmlString = rsaPrivKey.ToXmlString(true);
And now i would like to convert the string to bytes, something like this:
var xmlBytes = Encoding.Unicode.GetBytes(keyXmlString);
The question is wehat would be the right encoding to use there wehn converting xml string to bytes?
There is no “right” encoding here – it depends, on who is your consumer. You need to use the encoding, your consumer expects.
I strongly suggest to do something like
to make this more foolproof.