Which is the proper way to convert a byte[] to a string in order to have the expected Rijndael format?

余生长醉 提交于 2020-08-10 20:21:06

问题


I have problem when I transform a byte[] to a string.
I have used these ways so far:

  • System.Text.Encoding.UTF8.GetString(byteArray);

  • System.Text.Encoding.UTF8.GetString(byteArray);

I use Rijndael in order to encrypt some parameters to send them in an API and I follow this Microsoft-Documentation.

When I encrypt and decrypt as the documentation says everything works fine.
In the documentation there is no need for conversion byte[] to a string.

But in order to send it to the API I have to put them in an XML file. As a result I have to convert the encrypted byte[] to a string in order to send it. So when I send it in this ways I have Bad Credentials error, it is not acceptable. So I think that something is wrong with conversion.

When I make some tests with AES-site I have a nice string result. Like this:

For example:
The text : text is encrypted to something like this CfsfFYz5u+3psJy8RWV+HA==

This is exactly the expected format , like above (CfsfFYz5u+3psJy8RWV+HA==).

来源:https://stackoverflow.com/questions/62698275/which-is-the-proper-way-to-convert-a-byte-to-a-string-in-order-to-have-the-exp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!