chiefbiiko / base64 Goto Github PK
View Code? Open in Web Editor NEWbase64 strings from/to Uint8Arrays
License: MIT License
base64 strings from/to Uint8Arrays
License: MIT License
Hi I saw you made a reference in your code to this paragraph:
For this reason, modified Base64 for URL variants exist (such as base64url in RFC 4648), where the '+' and '/' characters of standard Base64 are respectively replaced by '-' and '_', so that using URL encoders/decoders is no longer necessary and have no impact on the length of the encoded value, leaving the same encoded form intact for use in relational databases, web forms, and object identifiers in general. Some variants allow or require omitting the padding '=' signs to avoid them being confused with field separators, or require that any such padding be percent-encoded.
Unfortunately you only implemented the optional base64url decoding for the -
and _
characters. The padding characters are not added back automatically to convert a URL-safe base64 string which obviously changes the base64 string length. This conversion is important for all JWT, JWS and JWE implementations. I changed it for myself with the following function based on this example in the JWS specification.
function addPaddingCharactersToBase64url(base64url: string): string {
if (base64url.length % 4 === 2) return base64url + "=="
if (base64url.length % 4 === 3) return base64url + "="
if (base64url.length % 4 === 1) throw new TypeError("Illegal base64url string!")
return base64url
}
Could I maybe convince you that adding this option is a good idea?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.