Skip to content

Provides full cross browser (and legacy browser) support for Base64 Encoding and Decoding true (not just merican) UTF-8 charset strings in Javascript. Will work with Base64 encoding and the UTF-8 charset on the .NET platform

Notifications You must be signed in to change notification settings

pmelander/base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

base64

Provides full cross browser (and legacy browser) support for Base64 Encoding and Decoding true (not just merican) UTF-8 charset strings in Javascript. Will work with Base64 encoding and the UTF-8 charset on the .NET platform.

It's a complete wonder that we in 2020 still don't have a decent international charset support for a standard nearly 30 years old, used by the majority of the world.

base64.encode in javascript

var encodedString = base64.encode(decodedString)

OR

var encodedString = btoa(decodedString)

base64.decode in javascript

var decodedString = base64.decode(encodedString)

OR

var decodedString = atob(encodedString)

encode in C#

var encodedString = Convert.ToBase64String(
    Encoding.UTF8.GetBytes(
        HttpUtility.UrlEncode("Decoded string")))

decode in C#

var decodedString = HttpUtility.UrlDecode(
    Encoding.UTF8.GetString(
        Convert.FromBase64String("RW5jb2RlZCUyMHN0cmluZw==")))

C# Extension for string

public static class StringExtensions
{
    public static string Base64Encode(this string str) =>
        Convert.ToBase64String(Encoding.UTF8.GetBytes(HttpUtility.UrlEncode(str ?? string.Empty)));

    public static string Base64Decode(this string str) =>
        HttpUtility.UrlDecode(Encoding.UTF8.GetString(Convert.FromBase64String(str)));
}

Usage

var encodedString = "Decoded string".Base64Encode()
var decodedString = "RW5jb2RlZCUyMHN0cmluZw==".Base64Decode()

About

Provides full cross browser (and legacy browser) support for Base64 Encoding and Decoding true (not just merican) UTF-8 charset strings in Javascript. Will work with Base64 encoding and the UTF-8 charset on the .NET platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published