New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@idearium/encryption

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@idearium/encryption - npm Package Compare versions

Comparing version

to
1.0.1

36

index.js

@@ -12,10 +12,12 @@ 'use strict';

algorithm = defaultAlgorithm,
inputEncoding = 'hex',
iv = required('iv'),
key = required('key'),
outputEncoding = 'utf8',
text = required('text')
} = {}) => {
const decipher = crypto.createDecipheriv(algorithm, key, iv);
let decrypted = decipher.update(text, 'hex', 'utf8');
let decrypted = decipher.update(text, inputEncoding, outputEncoding);
decrypted += decipher.final('utf8');
decrypted += decipher.final(outputEncoding);

@@ -27,10 +29,12 @@ return decrypted;

algorithm = defaultAlgorithm,
inputEncoding = 'utf8',
iv = required('iv'),
key = required('key'),
outputEncoding = 'hex',
text = required('text')
} = {}) => {
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
let encrypted = cipher.update(text, inputEncoding, outputEncoding);
encrypted += cipher.final('hex');
encrypted += cipher.final(outputEncoding);

@@ -42,7 +46,27 @@ return encrypted;

algorithm = defaultAlgorithm,
decryptInputEncoding = 'hex',
decryptOutputEncoding = 'utf8',
encryptInputEncoding = 'utf8',
encryptOutputEncoding = 'hex',
iv = required('iv'),
key = required('key')
} = {}) => ({
decrypt: ({ text }) => decrypt({ algorithm, iv, key, text }),
encrypt: ({ text }) => encrypt({ algorithm, iv, key, text })
decrypt: ({ text }) =>
decrypt({
algorithm,
inputEncoding: decryptInputEncoding,
iv,
key,
outputEncoding: decryptOutputEncoding,
text
}),
encrypt: ({ text }) =>
encrypt({
algorithm,
inputEncoding: encryptInputEncoding,
iv,
key,
outputEncoding: encryptOutputEncoding,
text
})
});

@@ -49,0 +73,0 @@

2

package.json
{
"name": "@idearium/encryption",
"version": "1.0.0",
"version": "1.0.1",
"description": "A package to make encrypting and decrypting plain text trivial.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -96,2 +96,17 @@ 'use strict';

});
test('can change the input and output encoding types', () => {
const o = atomic({
decryptInputEncoding: 'base64',
decryptOutputEncoding: 'utf8',
encryptInputEncoding: 'utf8',
encryptOutputEncoding: 'base64',
iv: 'b]7rDTw3BF2N6&vH',
key: 'dEDZvjbh)ADz3KzjpWW9TQL7(nfuyz2Q'
});
const { decrypt: decryptText, encrypt: encryptText } = o;
expect(encryptText({ text: 'plain text' })).toBe('p/ffun3NePOs7w==');
expect(decryptText({ text: 'p/ffun3NePOs7w==' })).toBe('plain text');
});
});

@@ -149,2 +164,17 @@

});
test('can change the input and output encoding types', () => {
const iv = 'b]7rDTw3BF2N6&vH';
const key = 'dEDZvjbh)ADz3KzjpWW9TQL7(nfuyz2Q';
expect(
decrypt({
inputEncoding: 'base64',
iv,
key,
outputEncoding: 'utf8',
text: 'p/ffun3NePOs7w=='
})
).toBe('plain text');
});
});

@@ -202,2 +232,17 @@

});
test('can change the input and output encoding types', () => {
const iv = 'b]7rDTw3BF2N6&vH';
const key = 'dEDZvjbh)ADz3KzjpWW9TQL7(nfuyz2Q';
expect(
encrypt({
inputEncoding: 'utf8',
iv,
key,
outputEncoding: 'base64',
text: 'plain text'
})
).toBe('p/ffun3NePOs7w==');
});
});