How to use base-64 - 10 common examples

To help you get started, we’ve selected a few base-64 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / base-64 / base-64-tests.ts View on Github external
import * as base64 from 'base-64';
import * as utf8 from 'utf8';

let text = 'foo © bar 𝌆 baz';
let bytes = utf8.encode(text);
let encoded = base64.encode(bytes);
// → 'Zm9vIMKpIGJhciDwnYyGIGJheg=='

encoded = 'Zm9vIMKpIGJhciDwnYyGIGJheg==';
bytes = base64.decode(encoded);
text = utf8.decode(bytes);

let version = base64.version;
github laurent22 / joplin / ReactNativeClient / lib / WebDavApi.js View on Github external
authToken() {
		if (!this.options_.username() || !this.options_.password()) return null;
		try {
			// Note: Non-ASCII passwords will throw an error about Latin1 characters - https://github.com/laurent22/joplin/issues/246
			// Tried various things like the below, but it didn't work on React Native:
			// return base64.encode(utf8.encode(this.options_.username() + ':' + this.options_.password()));
			return base64.encode(`${this.options_.username()}:${this.options_.password()}`);
		} catch (error) {
			error.message = `Cannot encode username/password: ${error.message}`;
			throw error;
		}
	}
github Krakabek / songSearchBot / src / providers / spotify.ts View on Github external
function getAuth(): Bluebird {
    // 
    const keys = `${config.get("spotify.clientId")}:${config.get("spotify.clientSecret")}`;
    const encodedKeys = base64.encode(utf8.encode(keys));
    return request({
        method: "POST",
        uri: "https://accounts.spotify.com/api/token",
        form: {
            grant_type: "client_credentials"
        },
        headers: {
            "Authorization": `Basic ${encodedKeys}`,
            "Content-Type": "application/x-www-form-urlencoded"
        },
        json: true
    }).then((response: SpotifyAuthResponse) => {
        token = response.access_token;
        const oneMinute = 60;
        const msInMin = 1000;
        const reAuthDelay = response.expires_in - oneMinute;
github liamray / nexl-js / tests / basic-auth-tests / basic-auth-tests.js View on Github external
function decode(auth) {
	try {
		return base64.decode(auth.substr(6));
	} catch (e) {
		return auth;
	}
}
github expo / expo / tools / expotools / src / Fixtures.ts View on Github external
res.setHeader(header, responseFixture.headers[header]);
    }

    let decodedData = base64.decode(responseFixture.data);
    let publishInfo = responseFixture.metadata ? responseFixture.metadata.publishInfo : null;
    decodedData = await _rewriteManifestAsync(
      publishInfo,
      req,
      decodedData,
      DEBUGGER_HOST_PLACEHOLDER,
      packagerServerUrl,
      MANIFEST_URL_PLACEHOLDER,
      manifestServerUrl
    );

    res.write(new Buffer(base64.encode(decodedData), 'base64'));
    res.end();
    console.log(`[${fixtureResponseId}] Responded to ${req.url}...`);
  };
github linfaservice / cloudgallery / app / pages / gallery / image-modal.component.js View on Github external
this.params = params;
        this.page = page;
        this.translate = translate;
        this.fonticon = fonticon;
        this.util = util;
        this.language = Platform.device.language;
        this.translate.setDefaultLang("en");
        this.translate.use(Platform.device.language.split("-")[0]);
        this.host = Settings.getString("host");
        this.username = Settings.getString("username");
        this.password = Settings.getString("password");
        this.rootdir = Settings.getString("rootdir");
        this.rootdir = (this.rootdir == null) ? "" : this.rootdir;
        this.headers = {
            "OCS-APIREQUEST": "true",
            "Authorization": "Basic " + Base64.encode(this.username + ':' + this.password)
        };
        this.item = params.context.item;
        this.loader = params.context.loader;
    }
    ImageModalComponent.prototype.ngOnInit = function () {
github heroiclabs / nakama-js / src / client.js View on Github external
message["collationId"] = uuidv4();

    const protocol = (this.ssl) ? 'https' : 'http';
    const url = `${protocol}://${this.host}:${this.port}${path}`

    if (this.verbose && window.console) {
      console.log("AuthenticateRequest: %s, %o", url, message);
    }

    var verbose = this.verbose;
    return fetch(url, {
      "method": "POST",
      "body": JSON.stringify(message),
      "headers": {
        "Accept-Language": this.lang,
        "Authorization": 'Basic ' + base64.encode(this.serverKey + ':'),
        "Content-Type": 'application/json',
        "Accept": 'application/json',
        "User-Agent": `nakama/${VERSION}`
      }
    }).then(function(response) {
      if (verbose && window.console) {
        console.log("AuthenticateResponse: %o", response);
      }

      return response.json();
    }).then(function(response) {
      if (verbose && window.console) {
        console.log("AuthenticateResponse (body): %o", response);
      }

      if (response.error) {
github linfaservice / cloudgallery / app / pages / gallery / gallery.component.ts View on Github external
this.translate.use(Platform.device.language.split("-")[0]).subscribe(()=> {
        this.host = Settings.getString("host");
        this.username = Settings.getString("username");
        this.password = Settings.getString("password");
        this.rootdir = Settings.getString("rootdir");  
        this.rootdir = (this.rootdir==null)? "":this.rootdir;
        this.headers = { 
          "OCS-APIREQUEST": "true",
          "Authorization": "Basic "+Base64.encode(this.username+':'+this.password)
        }            

        this.cache.images = new Array();
        this.home();
      });
    }
github FHIR / auto-ig-builder / triggers / deployment-trigger / index.js View on Github external
var secret = require('./secret.json');
var decode = require('base-64').decode;
var Api = require('kubernetes-client');

var config = {
  url: 'https://' + secret.clusterIp,
  ca: decode(secret.data['ca.crt']),
  auth: {
    bearer: decode(secret.data.token)
  }
};

const core = new Api.Core(config);

exports['container-deploy-trigger'] = function helloPubSub (event, callback) {
  console.log("called!");
  const pubsubMessage = event.data;
  const result = JSON.parse(Buffer.from(pubsubMessage.data, 'base64').toString());
  console.log("result", result);

  if (result.status !== 'SUCCESS'){
    return callback();
  }
github filipenatanael / whatsapp-clone-react-native / source / components / ChatsList.js View on Github external
componentWillMount() {
    this.props.fetchAllChats(base64.encode(this.props.email_logged_in));
    this.createDataSource(this.props.chatsList);
  }

base-64

A robust base64 encoder/decoder that is fully compatible with `atob()` and `btoa()`, written in JavaScript.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis