encryptionpackage
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
5768
2
2
2
128
+ Addednode-forge@^1.3.1
+ Addednode-forge@1.3.1(transitive)