How to use the @authenio/xml-encryption.encrypt function in @authenio/xml-encryption

To help you get started, we’ve selected a few @authenio/xml-encryption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tngan / samlify / src / libsaml.ts View on Github external
return reject(new Error('ERR_UNDEFINED_ASSERTION'));
        }

        const sourceEntitySetting = sourceEntity.entitySetting;
        const targetEntityMetadata = targetEntity.entityMeta;
        const doc = new dom().parseFromString(xml);
        const assertions = select("//*[local-name(.)='Assertion']", doc) as Node[];
        if (!Array.isArray(assertions)) {
          throw new Error('ERR_NO_ASSERTION');
        }
        if (assertions.length !== 1) {
          throw new Error('ERR_MULTIPLE_ASSERTION');
        }
        // Perform encryption depends on the setting, default is false
        if (sourceEntitySetting.isAssertionEncrypted) {
          xmlenc.encrypt(assertions[0].toString(), {
            // use xml-encryption module
            rsa_pub: new Buffer(utility.getPublicKeyPemFromCertificate(targetEntityMetadata.getX509Certificate(certUse.encrypt)).replace(/\r?\n|\r/g, '')), // public key from certificate
            pem: new Buffer('-----BEGIN CERTIFICATE-----' + targetEntityMetadata.getX509Certificate(certUse.encrypt) + '-----END CERTIFICATE-----'),
            encryptionAlgorithm: sourceEntitySetting.dataEncryptionAlgorithm,
            keyEncryptionAlgorighm: sourceEntitySetting.keyEncryptionAlgorithm,
          }, (err, res) => {
            if (err) {
              console.error(err);
              return reject(new Error('ERR_EXCEPTION_OF_ASSERTION_ENCRYPTION'));
            }
            if (!res) {
              return reject(new Error('ERR_UNDEFINED_ENCRYPTED_ASSERTION'));
            }
            const { encryptedAssertion: encAssertionPrefix } = sourceEntitySetting.tagPrefix;
            const encryptAssertionNode = new dom().parseFromString(`<${encAssertionPrefix}:EncryptedAssertion xmlns:${encAssertionPrefix}="${namespace.names.assertion}">${res}`);
            doc.replaceChild(encryptAssertionNode, assertions[0]);

@authenio/xml-encryption

[![Build Status](https://travis-ci.org/auth0/node-xml-encryption.png)](https://travis-ci.org/auth0/node-xml-encryption)

MIT
Latest version published 2 years ago

Package Health Score

55 / 100
Full package analysis

Popular @authenio/xml-encryption functions