Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

encrypt-uint8array

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encrypt-uint8array

Encrypt and decrypt an `Uint8Array` using another `Uint8Array` as password

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49
increased by58.06%
Maintainers
1
Weekly downloads
 
Created
Source

encrypt-uint8array Build Status

Encrypt and decrypt an Uint8Array using another Uint8Array as password

Highlights

  • Simple to use, hard to misuse
  • Does not reinvent the wheel (based on themis)
  • Written in TypeScript (you get autocomplete suggestions in your IDE!)

Install

$ npm install encrypt-uint8array

Usage

const {
	encryptUint8Array,
	decryptUint8Array,
	encodeString, // For convenience, but can be done with native TextEncoder
	decodeString  // For convenience, but can be done with native TextDecoder
} = require('encrypt-uint8array');

(async () => {
	const secret = encodeString('This is the secret');
	const password = encodeString('P4s$w0Rd!');
	const encrypted = await encryptUint8Array(secret, password);
	console.log(encrypted);
	//=> Uint8Array [ 0, 1, 1, 65, /* ... */, 103, 26 ]
	const decrypted = await decryptUint8Array(encrypted, password);
	console.log(decrypted);
	//=> Uint8Array [ 84, 104, 105, 115, /* ... */, 101, 116 ]
	console.log(decodeString(decrypted));
	//=> 'This is the secret'

	await decryptUint8Array(encrypted, encodeString('wrong password'));
	//=> DecryptionError: Unable to decrypt - password is incorrect or data is corrupted.
})();

API

encryptUint8Array(data, password)

Async function that encrypts data with password. Returns a new Uint8Array.

data

Type: Uint8Array

The data to be encrypted.

password

Type: Uint8Array

The Uint8Array to be used as password.

decryptUint8Array(encryptedData, password)

Async function that decrypts encryptedData with password. Returns a new Uint8Array.

If encryptedData is not valid or the password is incorrect, this function will throw a DecryptionError.

encryptedData

Type: Uint8Array

The data to be decrypted.

password

Type: Uint8Array

The Uint8Array to be used as password.

License

MIT © Pedro Augusto de Paula Barbosa

Keywords

FAQs

Package last updated on 16 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc