Miscellaneous Encoding Utilities for Crypto-related Objects in JavaScript
WARNING: At this time this solution should be considered suitable for research and experimentation, further code and security review is needed before utilization in a production application.
Introduction and Overview
This library is being developed to handle cryptographic data objects, e.g., PEM-formatted X.509 certificate, in JavaScript. Note that this library provides no cryptographic functions like encryption, but provides encoders, decoders and formatters of data formats related to cryptographic data objects. In particular, this introduces Base64(Url)-ArrayBuffer en/decoder, HexString-ArrayBuffer en/decoder and PEM-Binary formatter at this point. Moreover, this library is designed to be 'universal', i.e., it works both on most browsers and on Node.js just by importing from npm/source code.
Installation
At your project directory, do either one of the following.
Then you should import the package as follows.
import jseu from 'js-encoding-utils';
import jseu from 'jseu/dist/index.js';
Usage
Base64 <-> Binary
const encoded = jseu.encoder.encodeBase64(msg);
const decoded = jseu.encoder.decodeBase64(encoded);
Base64Url <-> Binary
const encoded = jseu.encoder.encodeBase64Url(msg);
const decoded = jseu.encoder.decodeBase64Url(encoded);
HexString <-> Binary
const encoded = jseu.encoder.arrayBufferToHexString(msg);
const decoded = jseu.encoder.hexStringToArrayBuffer(encoded);
PEM <-> Binary (usually DER encoding)
const certPEM ='-----BEGIN CERTIFICATE-----...';
const binCert = jseu.formatter.pemToBin(certPEM);
const pemCert = jseu.formatter.binToPem(binCert, 'certificate');
License
Licensed under the MIT license, see LICENSE
file.