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.7 to 1.0.8

29

encryption.js

@@ -128,3 +128,3 @@ // // // encryption.js

// encrypt.js
import { publicEncrypt } from 'crypto';
import forge from 'node-forge';

@@ -134,17 +134,24 @@ /**

* @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) {
// Encrypt the message using RSA-OAEP
const encryptedMessage = publicEncrypt(
{
key: publicKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha256', // Hash algorithm used in OAEP
// 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(),
},
Buffer.from(JSON.stringify(data))
);
});
// Convert to base64 for easier transport
return encryptedMessage.toString('base64');
// Convert to Base64
return forge.util.encode64(encryptedBytes);
}
{
"name": "encryptionpackage",
"version": "1.0.7",
"version": "1.0.8",
"main": "encryption.js",

@@ -21,4 +21,9 @@ "module": "encryption.js",

"dependencies": {
"encryptionpackage": "file:"
"encryptionpackage": "file:",
"node-forge": "^1.3.1"
},
"devDependencies": {
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4"
}
}
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