0.2.0 • Published 4 years ago

@starbase/encryption v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Encryption

Starbase Encryption

Starbase Encryption provides 256-bit AES-GCM encryption with HMAC signatures and PBKDF2 password stretching in the browser and in nodeJS. The web version uses the browser's built-in Web Crypto library. The node-webcrypto-ossl package is used server-side in NodeJS.

Adding Starbase Encryption to your Project

On the Web

<script src="/path/to/encryption.min.js"></script>

On the Web via jsdelivr CDN

<script src="https://cdn.jsdelivr.net/npm/@starbase/encryption/encryption.min.js"></script>

In NodeJS

npm install @starbase/encryption

Using Encryption

on the Web using encryption.min.js:

var encryption = Encryption();

in Node.js using @starbase/encryption:

var Encryption = require('@starbase/encryption');
var encryption = Encryption();

API Methods

encryption.encrypt(data, options)

Options

  • password
  • passwordBits
  • hmacBits
  • iterations

NOTE: The data parameter must be a string. The password options parameter is required (not optional) unless a passwordBits options parameter is provided.

Encryption a string with a password
encryption.encrypt('hello world', {
  "password":"mysecretpassword"
}).then(encrypted => {
  console.log(encrypted);
});
Response
"NTAwMDAw.LYLXNNjzCppoQr5GNR9wrVbX5HrRJg8045vKhdlEScA.gmRluIouvHmWkeqB.GQY-QDhvkGF0gaM1UYuv4cdho-SGpdj00L0h.GLRsEN-45OrZNM3Hwk96cLL7vMVxepYhEVM-LXJpejA"

encryption.decrypt(encrypted, options)

Options

  • password
  • passwordBits
  • hmacBits

NOTE: The encrypted parameter must be an encrypted string produced by the Encryption().encrypt() method. The password options parameter is required (not optional) unless a passwordBits options parameter is provided.

Decrypt data with a password
encryption.decrypt(encrypted, {
  "password":"mysecretpassword"
}).then(decrypted => {
  console.log(decrypted);
});
Response
"hello world"

More Information

Author

Hi, my name is Mike. Thanks for taking an interest in my work.