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

encryptionpackage

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encryptionpackage - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

165

encryption.js

@@ -1,12 +0,155 @@

import path from 'path';
// // // encryption.js
export default {
entry: './src/encryption.js', // Path to the encryption file
output: {
filename: 'bundle.js', // Output bundle file
path: path.resolve('dist'),
library: 'EncryptionPackage', // Name of the library/global object
libraryTarget: 'umd' // Ensures it works in various module systems
},
target: 'web', // Specifies the target environment is the browser
};
// // // Helper function to generate a random key
// // async function generateKey() {
// // return await crypto.subtle.generateKey(
// // { name: 'AES-GCM', length: 256 }, // Use AES-GCM with a 256-bit key
// // true, // Extractable
// // ['encrypt', 'decrypt'] // Usages for the key
// // );
// // }
// // // Encryption using Web Crypto API
// // export async function encrypt(text, key) {
// // const encoder = new TextEncoder();
// // const iv = crypto.getRandomValues(new Uint8Array(12)); // Generate random IV (12 bytes for GCM)
// // // Encrypt the text
// // const encrypted = await crypto.subtle.encrypt(
// // { name: 'AES-GCM', iv },
// // key,
// // encoder.encode(text)
// // );
// // return {
// // iv: Array.from(iv), // Convert to array for easy storage
// // content: Array.from(new Uint8Array(encrypted)) // Convert to array
// // };
// // }
// // // Decryption using Web Crypto API
// // export async function decrypt(encryptedData, key) {
// // const decoder = new TextDecoder();
// // const iv = new Uint8Array(encryptedData.iv);
// // const encryptedBytes = new Uint8Array(encryptedData.content);
// // const decrypted = await crypto.subtle.decrypt(
// // { name: 'AES-GCM', iv },
// // key,
// // encryptedBytes
// // );
// // return decoder.decode(decrypted);
// // }
// // // Function to create a new key and return it
// // export async function createNewKey() {
// // const key = await generateKey();
// // return key;
// // }
// // encryption.js
// // Helper function to generate a random key
// async function generateKey() {
// return await crypto.subtle.generateKey(
// { name: 'AES-GCM', length: 256 }, // Use AES-GCM with a 256-bit key
// true, // Extractable
// ['encrypt', 'decrypt'] // Usages for the key
// );
// }
// // Function to convert a Uint8Array to a Base64 string
// function uint8ArrayToBase64(uint8Array) {
// let binary = '';
// const len = uint8Array.byteLength;
// for (let i = 0; i < len; i++) {
// binary += String.fromCharCode(uint8Array[i]);
// }
// return window.btoa(binary);
// }
// // Function to convert a Base64 string back to a Uint8Array
// function base64ToUint8Array(base64) {
// const binary_string = window.atob(base64);
// const len = binary_string.length;
// const bytes = new Uint8Array(len);
// for (let i = 0; i < len; i++) {
// bytes[i] = binary_string.charCodeAt(i);
// }
// return bytes;
// }
// // Encryption using Web Crypto API
// export async function encrypt(text, key) {
// const encoder = new TextEncoder();
// const iv = crypto.getRandomValues(new Uint8Array(12)); // Generate random IV (12 bytes for GCM)
// // Encrypt the text
// const encrypted = await crypto.subtle.encrypt(
// { name: 'AES-GCM', iv },
// key,
// encoder.encode(text)
// );
// // Convert to Base64 string for easy storage/transmission
// const encryptedBase64 = uint8ArrayToBase64(new Uint8Array(encrypted));
// const ivBase64 = uint8ArrayToBase64(iv); // Convert IV to Base64
// return {
// iv: ivBase64, // Store IV as a Base64 string
// content: encryptedBase64 // Store encrypted content as a Base64 string
// };
// }
// // Decryption using Web Crypto API
// export async function decrypt(encryptedData, key) {
// const decoder = new TextDecoder();
// const iv = base64ToUint8Array(encryptedData.iv); // Convert Base64 IV back to Uint8Array
// const encryptedBytes = base64ToUint8Array(encryptedData.content); // Convert Base64 content back to Uint8Array
// const decrypted = await crypto.subtle.decrypt(
// { name: 'AES-GCM', iv },
// key,
// encryptedBytes
// );
// return decoder.decode(decrypted);
// }
// // Function to create a new key and return it
// export async function createNewKey() {
// const key = await generateKey();
// return key;
// }
// encrypt.js
import forge from 'node-forge';
/**
* Encrypts the given message using RSA-OAEP.
* @param {Object} data - The data to encrypt (should include uuid and token).
* @param {string} publicKey - The RSA public key in PEM format.
* @returns {string} - The encrypted message as a Base64 string.
*/
export function encryptData(data, publicKey) {
// Convert the public key from PEM format to a forge public key
const forgePublicKey = forge.pki.publicKeyFromPem(publicKey);
// Convert data to a string and then to a byte array
const dataString = JSON.stringify(data);
const dataBytes = forge.util.encodeUtf8(dataString);
// Encrypt the data using RSA-OAEP
const encryptedBytes = forgePublicKey.encrypt(dataBytes, 'RSA-OAEP', {
md: forge.md.sha256.create(),
mgf1: {
md: forge.md.sha1.create(),
},
});
// Convert to Base64
return forge.util.encode64(encryptedBytes);
}

8

package.json
{
"name": "encryptionpackage",
"version": "1.0.9",
"version": "1.0.10",
"main": "encryption.js",

@@ -27,3 +27,7 @@ "module": "encryption.js",

"webpack-cli": "^5.1.4"
}
},
"files": [
"dist",
"src"
]
}
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