Sure, here is how to encode and decode a base64 string in C#:
Encoding a string to base64
To encode a string to base64, you can use the Convert.ToBase64String() method. This method takes a byte array as a parameter and returns a base64 encoded string.
For example, the following code encodes the string "Hello, world!" to base64:
To decode a base64 string, you can use the Convert.FromBase64String() method. This method takes a base64 encoded string as a parameter and returns a byte array.
For example, the following code decodes the base64 string "SGVsbG8gV29ybGQh" to the string "Hello, world!":
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Sure, here is how to encode and decode a base64 string in C#:
Encoding a string to base64
To encode a string to base64, you can use the
Convert.ToBase64String()method. This method takes a byte array as a parameter and returns a base64 encoded string.For example, the following code encodes the string "Hello, world!" to base64:
C#
Decoding a base64 string
To decode a base64 string, you can use the
Convert.FromBase64String()method. This method takes a base64 encoded string as a parameter and returns a byte array.For example, the following code decodes the base64 string "SGVsbG8gV29ybGQh" to the string "Hello, world!":
C#
Here is a complete example of how to encode and decode a base64 string in C#:
C#