PHP 8.2.30
Preview: security.js Size: 2.02 KB
/home/byroehnu/.trash/node_modules11/flutterwave-node-v3/lib/security.js

// var createHash = require('sha.js');
var crypto = require('crypto');//crypto is faster and managed by NodeJs

// this is the getKey function that generates an encryption Key  
// for you by passing your Secret Key as a parameter.
function getKey(seckey) {
    var md5 = require('md5');
    var keymd5 = md5(seckey);
    var keymd5last12 = keymd5.substr(-12);

    var seckeyadjusted = seckey.replace('FLWSECK-', '');
    var seckeyadjustedfirst12 = seckeyadjusted.substr(0, 12);

    return seckeyadjustedfirst12 + keymd5last12;
}

// This is the encryption function that encrypts your payload
// by passing the stringified format and your encryption Key.
// function encrypt(key, text)
// {
//     console.log("Key:   "+key)

//     console.log("Txt:   "+text)
//     var forge    = require('node-forge'); 
//     var cipher   = forge.cipher.createCipher('3DES-ECB', forge.util.createBuffer(key));
//     cipher.start({iv:''});
//     cipher.update(forge.util.createBuffer(text, 'utf-8'));
//     cipher.finish();
//     var encrypted = cipher.output;
//     return ( forge.util.encode64(encrypted.getBytes()) );
// }

function encrypt(key, text) {
    var forge = require("node-forge");
    var cipher = forge.cipher.createCipher(
        "3DES-ECB",
        forge.util.createBuffer(key)
    );
    cipher.start({
        iv: ""
    });
    cipher.update(forge.util.createBuffer(text, "utf-8"));
    cipher.finish();
    var encrypted = cipher.output;
    return forge.util.encode64(encrypted.getBytes());
}

function getIntegrityHash(data, pubkey, seckey) {

    var objectKeys = Object.keys(data);
    objectKeys.sort();
    var hashString = "";
    objectKeys
        .forEach(function (ok) {

            if (ok == 'integrity_hash') return; // don't include int hash
            hashString += data[ok];

        });
    hashString += seckey;
    var hash = crypto.createHash('sha256').update(hashString, 'utf8').digest('hex');
    return hash;
}


module.exports = {
    getEncryptionKey: getKey,
    encrypt: encrypt,
    getIntegrityHash: getIntegrityHash
}

Directory Contents

Dirs: 0 × Files: 20

Name Size Perms Modified Actions
354 B lrw-r--r-- 2026-02-21 00:53:50
Edit Download
4.39 KB lrw-r--r-- 2026-02-21 00:53:52
Edit Download
698 B lrw-r--r-- 2026-02-21 00:53:52
Edit Download
2.01 KB lrw-r--r-- 2026-02-21 00:53:54
Edit Download
1.72 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
244 B lrw-r--r-- 2026-02-21 00:54:02
Edit Download
337 B lrw-r--r-- 2026-02-21 00:54:04
Edit Download
787 B lrw-r--r-- 2026-02-21 00:54:08
Edit Download
1016 B lrw-r--r-- 2026-02-21 00:54:08
Edit Download
331 B lrw-r--r-- 2026-02-21 00:54:10
Edit Download
826 B lrw-r--r-- 2026-02-21 00:54:10
Edit Download
363 B lrw-r--r-- 2026-02-21 00:54:18
Edit Download
750 B lrw-r--r-- 2026-02-21 00:54:18
Edit Download
674 B lrw-r--r-- 2026-02-21 00:54:18
Edit Download
924 B lrw-r--r-- 2026-02-21 00:54:20
Edit Download
1.13 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
973 B lrw-r--r-- 2026-02-21 00:54:22
Edit Download
700 B lrw-r--r-- 2026-02-21 00:54:22
Edit Download
1.51 KB lrw-r--r-- 2026-02-21 00:54:22
Edit Download
2.02 KB lrw-r--r-- 2026-02-21 00:54:24
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).