npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

secure-pgp-storage

v1.1.1

Published

Class on top of OpenPGP.js

Downloads

464

Readme

secure-pgp-storage

secure-pgp-storage is a class on top of OpenPGP.js

Table of Contents

secure-pgp-storage

  • The secure-pgp-storage class is designed to minimize code when working with the OpenPGP.js library.

  • The index.js bundle works well in Node.js. It is used by default when you require('secure-pgp-storage') in Node.js.

Getting started

Node.js

Install secure-pgp-storage using npm:

npm install secure-pgp-storage

And import it as a CommonJS module:

const sPGPs = require('secure-pgp-storage');

Examples

Here are some examples of how to use secure-pgp-storage. Please review the test.js file to understand how the secure-pgp-storage class works.

Generate new ECC key pair

The createStorage function creates a new ECC key pair and stores them in class variables.

(async () => {
	await sPGPs.createStorage('John Smith', '[email protected]', '1q2w3e4r5t6y7u8i9o0p');
	console.log('Nickname:', sPGPs.nickname);
	console.log('E-mail:', sPGPs.email);
	console.log('Fingerprint:', sPGPs.fingerprint);
	console.log('Public key:');
	console.log(sPGPs.publicKeyArmored);
})();

Checking class variables for data

The createStorage function creates a new ECC key pair and stores them in class variables.

(async () => {
	console.log('All data is activated:', await sPGPs.checkAllData());
})();

Encrypt String data with PGP keys

Encryption will use the algorithm preferred by the public (encryption) key (defaults to aes256 for keys generated in OpenPGP.js). The signature parameter is optional and is required for signing.

(async () => {
	const recipientPublicKeyArmored = sPGPs.publicKeyArmored;	// For example, we will use our public key.
	let encrypted = await sPGPs.encryptMessage('Hello world!', recipientPublicKeyArmored, signature = true);
	console.log('Encrypted message:');
	console.log(encrypted);
	console.log('Check message:', await sPGPs.checkMessage(encrypted));
})();

Decrypt String data with PGP keys

Decryption will use the algorithm used for encryption. The senderPublicKeyArmored parameter is optional and required to verify the signature.

(async () => {
	const senderPublicKeyArmored = sPGPs.publicKeyArmored;
	let decrypted = await sPGPs.decryptMessage(encrypted, senderPublicKeyArmored);
	console.log('Decrypted message:');
	console.log(decrypted);
	console.log(decrypted.data);
	console.log(decrypted.signatures[0].keyID.toHex());
	console.log(await decrypted.signatures[0].verified);
})();

Symmetric encryption of String data with compression

By default, encryptMessageSymmetricallyWithCompression will use openpgp.enums.compression.zlib symmetric encryption compression.

(async () => {
	encrypted = await sPGPs.encryptMessageSymmetricallyWithCompression('Hello again!', '1234567890');
	console.log('Encrypted message:');
	console.log(encrypted);
	console.log('Check message:', await sPGPs.checkMessage(encrypted));
})();

Symmetric decryption of String data with compression

(async () => {
	decrypted = await sPGPs.decryptMessageSymmetricallyWithCompression(encrypted, '1234567890');
	console.log('Decrypted message:');
	console.log(decrypted);
})();

Storage encryption

The encryptStorage function puts publicKeyArmored and privateKeyArmored into JSON and encrypts them with symmetric encryption using the password that was used to create the key pair.

(async () => {
	const encryptedStorage = await sPGPs.encryptStorage();
	console.log('Encrypted storage:');
	console.log(encryptedStorage);
	console.log('Check message:', await sPGPs.checkMessage(encryptedStorage));
	console.log('encodeURIComponent (for file href html):', await sPGPs.generateSecureFile());	
})();

Clearing data from storage

The eraseAllData function clears class variables.

(async () => {
	await sPGPs.eraseAllData();
	console.log('Nickname:', sPGPs.nickname);
	console.log('E-mail:', sPGPs.email);
	console.log('Fingerprint:', sPGPs.fingerprint);
	console.log('Public key:');
	console.log(sPGPs.publicKeyArmored);
	console.log('All data is activated:', await sPGPs.checkAllData());
})();

Storage decryption

The decryptStorage function decrypts a message with a key pair inside. After parsing the JSON and reading the keys, the class variables are filled.

(async () => {
	const decryptedStorage = await sPGPs.decryptStorage(encryptedStorage, '1q2w3e4r5t6y7u8i9o0p');
	console.log('Decrypted storage:', decryptedStorage);
	console.log('Nickname:', sPGPs.nickname);
	console.log('E-mail:', sPGPs.email);
	console.log('Fingerprint:', sPGPs.fingerprint);
	console.log('Public key:');
	console.log(sPGPs.publicKeyArmored);
	console.log('All data is activated:', await sPGPs.checkAllData());
})();

License

GNU Lesser General Public License (3.0 or any later version). Please take a look at the LICENSE file for more information.