![]() Here's the equivalent program in C#, my second-most favorite language: public static string ToBase64(string value)īyte bytes = .GetBytes(value) require "base64"Įncoded = Base64.encode64("Ruby on Rails") # "UnVieSBvbiBSYWlscw=\n"ĭecoded = code64(encoded) # "Ruby on Rails" Here is the Ruby code that takes some text as input and converts it into Base-64 encoded string. Makes sense? How to Encode and Decode Base64Īll programming languages have support for encoding and decoding data to and from the Base64 format. Now you could send or store that text anywhere and anyhow you like, without worrying whether some legacy device, protocol or software won't misinterpret the raw binary data to corrupt your file. You could first convert it to binary, and then Base64 encode it to get corresponding ASCII text. Imagine, instead of my name, you had an image or a sensitive file (PDF, text, video, anything, really), and you wanted to store it as text. What exactly did we achieve by converting "Akshay" to "QWtzaGF5"? ![]() The name "Akshay" is represented in Base64 as QWtzaGF5.Īt first glance, the benefit of Base64 encoding is not quite obvious.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |