Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/junkurihara/jseu
Miscellaneous Encoding Utilities for Crypto-related Objects in JavaScript
https://github.com/junkurihara/jseu
Last synced: about 5 hours ago
JSON representation
Miscellaneous Encoding Utilities for Crypto-related Objects in JavaScript
- Host: GitHub
- URL: https://github.com/junkurihara/jseu
- Owner: junkurihara
- License: mit
- Created: 2018-09-21T05:49:59.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2024-11-11T22:37:02.000Z (4 days ago)
- Last Synced: 2024-11-11T23:28:40.781Z (4 days ago)
- Language: TypeScript
- Homepage:
- Size: 1.47 MB
- Stars: 2
- Watchers: 5
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Miscellaneous Encoding Utilities for Crypto-related Objects in JavaScript
--
[![npm version](https://badge.fury.io/js/js-encoding-utils.svg)](https://badge.fury.io/js/js-encoding-utils)
![Unit Test](https://github.com/junkurihara/jseu/actions/workflows/ci.yml/badge.svg)
[![codecov](https://codecov.io/gh/junkurihara/jseu/branch/develop/graph/badge.svg)](https://codecov.io/gh/junkurihara/jseu)
[![Maintainability](https://api.codeclimate.com/v1/badges/771abd93ae5d986f1e0a/maintainability)](https://codeclimate.com/github/junkurihara/jseu/maintainability)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)> **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.- From npm/yarn:
```shell
$ npm install --save js-encoding-utils // npm
$ yarn add js-encoding-utils // yarn
```- From GitHub:
```shell
$ git clone https://github.com/junkurihara/jseu.git
```Then you should import the package as follows.
```javascript
import jseu from 'js-encoding-utils'; // for npm
import jseu from 'jseu/dist/index.js'; // for github
```# Usage
## Base64 <-> Binary
```javascript
// msg is an ArrayBuffer or Typed Array
const encoded = jseu.encoder.encodeBase64(msg);
// now you get Base64 stringconst decoded = jseu.encoder.decodeBase64(encoded);
// now you get the original message in Uint8Array
```## Base64Url <-> Binary
```javascript
// msg is an ArrayBuffer or Typed Array
const encoded = jseu.encoder.encodeBase64Url(msg);
// now you get Base64Url stringconst decoded = jseu.encoder.decodeBase64Url(encoded);
// now you get the original message in Uint8Array
```## HexString <-> Binary
```javascript
// msg is an ArrayBuffer or Typed Array
const encoded = jseu.encoder.arrayBufferToHexString(msg);
// now you get the hex-stringified message stringconst decoded = jseu.encoder.hexStringToArrayBuffer(encoded);
// now you get the original message in Uint8Array
```## PEM <-> Binary (usually DER encoding)
```javascript
// X.509 formatted certificate
const certPEM ='-----BEGIN CERTIFICATE-----...';const binCert = jseu.formatter.pemToBin(certPEM);
// now you get the DER encoded certificate in Uint8Arrayconst pemCert = jseu.formatter.binToPem(binCert, 'certificate');
// now you get the original certificate.
```# License
Licensed under the MIT license, see `LICENSE` file.