Socket
Socket
Sign inDemoInstall

easycrypt

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easycrypt - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

.babelrc

47

easycrypt.js

@@ -1,19 +0,18 @@

"use strict";
import randomstring from 'randomstring';
import crypto from 'crypto';
const randomstring = require("randomstring");
const genString = () => randomstring.generate({ length: 8 });
const algorithm = 'aes-256-gcm';
const password = process.env.EasyCryptPW
|| new Error('Must provide EasyCryptPW as a env variable');
const crypto = require('crypto'),
algorithm = 'aes-256-gcm',
password = process.env.EasyCryptPW || new Error("Must provide EasyCryptPW as a env variable");
function encrypt(text, iv) {
iv || new Error("Must provide iv to encrypt");
if (!iv) Error('Must provide iv to encrypt');
const cipher = crypto.createCipheriv(algorithm, password, iv);
let crypted = cipher.update(text, 'utf8', 'hex');
crypted += cipher.final('hex');
const tag = cipher.getAuthTag();
let crypted = cipher.update(text, 'utf8', 'hex');
crypted += cipher.final('hex');
const tag = cipher.getAuthTag();
return {
content: crypted,
tag: tag
tag,
};

@@ -30,23 +29,21 @@ }

class EasyCrypt {
encrypt(text) {
const salt = genString();
text += `+${salt}`;
const iv = genString();
let ret = encrypt(text, iv);
ret.content = ret.content + `+${iv}`;
export default class EasyCrypt {
static encrypt(text) {
let finalText = text;
const salt = genString();
finalText += `+${salt}`;
const iv = genString();
const ret = encrypt(finalText, iv);
ret.content += `+${iv}`;
return ret;
}
decrypt(cryptObj) {
const [crypted, iv] = cryptObj.content.split("+");
static decrypt(cryptObj) {
const [crypted, iv] = cryptObj.content.split('+');
const decryptObj = {};
decryptObj.content = crypted;
decryptObj.tag = cryptObj.tag;
decryptObj.tag = cryptObj.tag;
const dcrypt = decrypt(decryptObj, iv);
return dcrypt.split("+")[0];
return dcrypt.split('+')[0];
}
}
module.exports = EasyCrypt;
"use strict";
const EasyCrypt = require("../easycrypt.js");
const ez = new EasyCrypt();
import EasyCrypt from "../easycrypt";
let stringToEncrypt = "This is easy.";
let crypted = ez.encrypt(stringToEncrypt);
let crypted = EasyCrypt.encrypt(stringToEncrypt);
console.log(`Original: ${stringToEncrypt}`)
console.log(`Crypted: ${crypted.content}`);
console.log(`Decrypted: ${ez.decrypt(crypted)}`);
console.log(`Decrypted: ${EasyCrypt.decrypt(crypted)}`);
{
"name": "easycrypt",
"version": "0.1.1",
"version": "0.1.2",
"description": "A simple bi-directional salting and encryption system designed for securing authentication tokens.",
"main": "easycrypt.js",
"scripts": {
"test": "EasyCryptPW='3zTvzr3p67VC61jmV54rIYu1545x4TlY' mocha test",
"ex": "EasyCryptPW='3zTvzr3p67VC61jmV54rIYu1545x4TlY' node ex/intro-example.js"
"test": "EasyCryptPW='3zTvzr3p67VC61jmV54rIYu1545x4TlY' mocha -r @std/esm test",
"ex": "EasyCryptPW='3zTvzr3p67VC61jmV54rIYu1545x4TlY' node -r @std/esm ex/intro-example.js"
},

@@ -34,5 +34,22 @@ "repository": {

"devDependencies": {
"@std/esm": "^0.20.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0",
"celebs": "^0.1.0",
"chai": "^4.1.2",
"mocha": "^4.0.1"
"eslint": "^4.16.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.6.0",
"is": "^3.2.1",
"mocha": "^3.5.3",
"randexp": "^0.4.6",
"webpack": "^3.10.0"
}
}
"use strict";
const chai = require("chai");
const EasyCrypt = require("../easycrypt.js");
const ez = new EasyCrypt();
import chai from "chai";
import EasyCrypt from "../easycrypt";

@@ -10,3 +9,3 @@ describe("EasyCrypt", () => {

it("Return from encrypt should have tag (Buffer) and content (string)", () => {
let out = ez.encrypt("Easy");
let out = EasyCrypt.encrypt("Easy");
chai.expect(!!out.content && !!out.tag).to.be.true;

@@ -18,5 +17,5 @@ chai.expect(out.tag.__proto__.constructor.name === "Buffer").to.be.true;

let input = "Easy";
chai.expect(input === ez.decrypt(ez.encrypt(input))).to.be.true;
chai.expect(input === EasyCrypt.decrypt(EasyCrypt.encrypt(input))).to.be.true;
})
});
});
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