Convert String to Base64
First convert the string to a byte array and then use the Convert.ToBase64String() method to convert the byte array to a Base64 string.
C#
byte[] byt = System.Text.Encoding.UTF8.GetBytes(strOriginal);
// convert the byte array to a Base64 string
strModified = Convert.ToBase64String(byt);
VB.NET
Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(strOriginal)
' convert the byte array to a Base64 string
strModified = Convert.ToBase64String(byt)
Convert Base64 string to String
In order to convert a Base64 string back to the original string, use FromBase64String(). First FromBase64String() converts the string to a byte array and then use the relevant Encoding method to convert the byte array to a string, in our case UTF8.GetString();
C#
byte[] b = Convert.FromBase64String(strModified);
strOriginal = System.Text.Encoding.UTF8.GetString(b);
VB.NET
Dim b As Byte() = Convert.FromBase64String(strModified)
strOriginal = System.Text.Encoding.UTF8.GetString(b)
Thanks for this code.
ReplyDeleteit is really useful for me
That was help full
ReplyDeleteThanks
Thats it ! simple
ReplyDeleteThankssssss
This was really lucid and it worked. Thnaks.
ReplyDeletewow Excellent..........
ReplyDeleteThank you so much for this! :)
ReplyDeleteTime Saving Code
ReplyDeleteThanks
thank you!!!
ReplyDeleteThanks
ReplyDeleteThanks very much for this sample
ReplyDeleteI'm not a developer, i always use the free online base64 string converter to encode and decode base64.
ReplyDeleteTHANK YOU SO MUCH ! YOU ARE THE BEST ! I CAN'T SHOW YOU HOW I'M HAPPY :D, AGAIN : THANK YOU SO MUCH, AND AGAIN : THANK YOU SO MUCH MY FRIEND, YOU ARE AWESOME ;DDDDDDDDDD
ReplyDelete