RSACryptoServiceProvider.ToXmlString();编码
我从我的 RSA 密钥创建 xml 字符串:
var keyXmlString = rsaPrivKey.ToXmlString(true);
现在我想将字符串转换为字节,如下所示:
var xmlBytes = Encoding.Unicode.GetBytes(keyXmlString);
问题是,将 xml 字符串转换为字节时,使用正确的编码吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里没有“正确”的编码——这取决于谁是你的消费者。您需要使用消费者期望的编码。
我强烈建议做一些事情,
让这更加万无一失。
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.
只要编码和解码保持一致,使用哪种编码并不重要。
As long as you're consistent with the encoding and decoding it really doesn't matter which encoding you use.