Comments (1)
I just "discovered" this same issue. That will teach me to read the issues and not just blindly assume all is well ;-). I discovered mine when using this code to decode a REAL JWT returned from Azure ID services. The header segment of the JWT needs to be decoded to get the "kid" value to get the correct public key certificate from microsoft for subsequent verification of the JWT. The value returned in my case turns out to be a multiple of 4 so it provides the redundant padding. as above. My fix was slightly different but has the same effect:
public string function convertToBase64( required string input ) {
input = replace( input, "-", "+", "all" );
input = replace( input, "_", "/", "all" );
var paddingLength = ( 4 - ( len( input ) % 4 ) );
if (paddingLength EQ 4) {
paddingLength = 0;
}
return( input & repeatString( "=", paddingLength ) );
}
Now that I look at it, I like the following even better:
public string function convertToBase64( required string input ) {
input = replace( input, "-", "+", "all" );
input = replace( input, "_", "/", "all" );
// if the input is a multiple of 4, no padding is needed. Simply return it.
if (len(input) % 4 EQ 0) {
return input;
}
// otherwise pad the input with "=" until it is a multiple of four.
var paddingLength = ( 4 - ( len( input ) % 4 ) );
return( input & repeatString( "=", paddingLength ) );
}
from jsonwebtokens.cfc.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonwebtokens.cfc.