I’m new to C# development,
the following code is Convert.ToBase64String problem,
i don’t know how to solve it.
byte[] str1Byte = System.Text.Encoding.UTF8.GetBytes("xyz123");
String plaintext = Convert.ToBase64String(str1Byte);
byte[] plaintext_bytes = System.Text.Encoding.UTF8.GetBytes(plaintext);
Console.WriteLine("base64 plaintext: " + plaintext);
Console.WriteLine("plaintext_bytes to String: " +
System.Text.Encoding.UTF8.GetString(plaintext_bytes));
Console.WriteLine("ToBase64String(plaintext_bytes) : " +
Convert.ToBase64String(plaintext_bytes));
Result:
base64 plaintext: eHl6MTIz
plaintext_bytes to String: eHl6MTIz
ToBase64String(plaintext_bytes) : ZUhsNk1USXo=
I expect the output of “Convert.ToBase64String(plaintext_bytes))” to be “eHl6MTIz“, not “ZUhsNk1USXo=“.
You’re trying to Base64 encode something that is already Base64 encoded:
As mentioned, you need to go FROM base 64