Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
xml-encryption
Advanced tools
[![Build Status](https://travis-ci.org/auth0/node-xml-encryption.png)](https://travis-ci.org/auth0/node-xml-encryption)
The xml-encryption npm package provides tools for encrypting and decrypting XML data. It supports various encryption algorithms and allows for the secure handling of XML documents.
Encrypting XML Data
This feature allows you to encrypt XML data using a specified encryption algorithm and keys. The code sample demonstrates how to encrypt an XML string using RSA and AES256-CBC.
const xmlenc = require('xml-encryption');
const xml = '<root><name>John Doe</name></root>';
const options = { rsa_pub: 'public_key.pem', pem: 'private_key.pem', encryptionAlgorithm: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc' };
xmlenc.encrypt(xml, options, function(err, result) {
if (err) console.error(err);
console.log('Encrypted XML:', result);
});
Decrypting XML Data
This feature allows you to decrypt previously encrypted XML data using the appropriate private key. The code sample demonstrates how to decrypt an encrypted XML string.
const xmlenc = require('xml-encryption');
const encryptedXml = '...'; // Encrypted XML string
const options = { key: 'private_key.pem' };
xmlenc.decrypt(encryptedXml, options, function(err, result) {
if (err) console.error(err);
console.log('Decrypted XML:', result);
});
The xml2js package is used for parsing XML to JavaScript objects and vice versa. While it does not provide encryption functionalities, it is useful for handling XML data in JavaScript applications.
The xml-crypto package provides tools for XML digital signatures and encryption. It offers similar functionalities to xml-encryption but also includes support for XML signatures, making it a more comprehensive solution for XML security.
The node-forge package is a comprehensive library for cryptographic operations in JavaScript, including encryption, decryption, and key generation. While it is not specific to XML, it can be used to implement custom XML encryption and decryption solutions.
W3C XML Encryption implementation for node.js (http://www.w3.org/TR/xmlenc-core/)
Supports node >= 8
npm install xml-encryption
var xmlenc = require('xml-encryption');
var options = {
rsa_pub: fs.readFileSync(__dirname + '/your_rsa.pub'),
pem: fs.readFileSync(__dirname + '/your_public_cert.pem'),
encryptionAlgorithm: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
keyEncryptionAlgorithm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p',
disallowEncryptionWithInsecureAlgorithm: true,
warnInsecureAlgorithm: true
};
xmlenc.encrypt('content to encrypt', options, function(err, result) {
console.log(result);
}
Result:
<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes-256-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
</e:EncryptionMethod>
<KeyInfo>
<X509Data><X509Certificate>MIIEDzCCAveg... base64 cert... q3uaLvlAUo=</X509Certificate></X509Data>
</KeyInfo>
<e:CipherData>
<e:CipherValue>sGH0hhzkjmLWYYY0gyQMampDM... encrypted symmetric key ...gewHMbtZafk1MHh9A==</e:CipherValue>
</e:CipherData>
</e:EncryptedKey>
</KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>V3Vb1vDl055Lp92zvK..... encrypted content.... kNzP6xTu7/L9EMAeU</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
var options = {
key: fs.readFileSync(__dirname + '/your_private_key.key'),
disallowDecryptionWithInsecureAlgorithm: true,
warnInsecureAlgorithm: true
};
xmlenc.decrypt('<xenc:EncryptedData ..... </xenc:EncryptedData>', options, function(err, result) {
console.log(result);
}
// result
decrypted content
Currently the library supports:
EncryptedKey to transport symmetric key using:
EncryptedData using:
Insecure Algorithms can be disabled via disallowEncryptionWithInsecureAlgorithm
/disallowDecryptionWithInsecureAlgorithm
flags when encrypting/decrypting. This flag is off by default in 0.x versions.
A warning will be piped to stderr
using console.warn() by default when the aforementioned algorithms are used. This can be disabled via the warnInsecureAlgorithm
flag.
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
This project is licensed under the MIT license. See the LICENSE file for more info.
Release notes may be found under github release page: https://github.com/auth0/node-xml-encryption/releases
FAQs
[![Build Status](https://travis-ci.org/auth0/node-xml-encryption.png)](https://travis-ci.org/auth0/node-xml-encryption)
The npm package xml-encryption receives a total of 0 weekly downloads. As such, xml-encryption popularity was classified as not popular.
We found that xml-encryption demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 43 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.