Base64 Encoding / Decoding

🚧

Encoding at Goodays

Encoding work only with the cz_user and not with Additional Information (cz_x_).

How to encode/decode base 64

You have two solutions to encode or decode in base64:

  • Use a website to decode or encode
  • Be local with your macOS (or others) terminal !

Encode locally

Use this command:

echo 'Michael|Scott|[email protected]|0123456789|123ABC' | base64

Result : TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJDCg==

Decode locally

Use this command:

base64 -D <<< TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJDCg==

Result : Michael|Scott|[email protected]|0123456789|123ABC

Some examples in various languages

PHP

<?php 
function base64_urlsafe_encode($data) { 
  return strtr(base64_encode($data), '+/', '-_');
} 

function base64_urlsafe_decode($data) { 
  return base64_decode(strtr($data, '-_', '+/')); 
} 

$customer_info = "Michael|Scott|[email protected]|0123456789|123ABC";

$cz_user = base64_urlsafe_encode($customer_info);

echo $cz_user;
//TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJD
?>

Python

import base64

customer_info = 'Michael|Scott|[email protected]|0123456789|123ABC'

cz_user = base64.urlsafe_b64encode(customer_info)

print cz_user
#TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJD

JavaScript

base64_encode = function(unencoded) {
  return new Buffer(unencoded || '').toString('base64');
};

base64_decode = function(encoded) {
  return new Buffer(encoded || '', 'base64').toString('utf8');
};

base64_urlsage_encode = function(unencoded) {
  var encoded = base64_encode(unencoded);
  return encoded.replace(/\+/g, '-').replace(/\//g, '_');
};

base64_urlsafe_decode = function(encoded) {
  encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
  return base64_decode(encoded);
};

var customer_info = "Michael|Scott|[email protected]|0123456789|123ABC"

var cz_user = base64_urlsage_encode(customer_info)

console.log(cz_user)
//TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJD