1.0.0 • Published 7 years ago
hex-xor-cipher v1.0.0
hex-xor-cipher
xor cipher for shift base encrypting and decrypting hexadecimal string
Adds an extra layer of protection to your already encrypted code's hex output by essentially turning it into nothing but valid hex.
Installation
demo: https://angeal185.github.io/hex-xor-cipher/
npm
$ npm install hex-xor-cipher --savebower
$ bower install hex-xor-cipher --savegit
$ git clone git@github.com:angeal185/hex-xor-cipher.gitnodejs
const hx = require('hex-xor-cipher')browser
<script src="./path-to/lodash.min.js"></script>
<script src="./dist/hex-xor.min.js"></script>info
- Adds a shif-based hex-xor to a valid hex string
000000with a shift value of1would become1f1f1f000000with a shift value of2would become2e2e2e000000with a shift value of1and{reverse: true}would becomef1f1f1000000with a shift value of1and{uppercase: true}would becomeF1F1F1000000with a shift value of1and{buff: [1,2]}might become73f1f1f1c48e
API
//default options
{
reverse: false, // {boolean} ~ reverse hex string
uppercase: false, // {boolean} ~ output uppercase hex
buff: false // {boolean/array} ~ prepend/append random hex buffer
}
/*
* reverse should be set to either true or false for both
encrypt/decrypt ~ default: false
* buff accepts either a boolean for false or an array for true.
~ [1,2] would prepend/slice 1 byte(2 hex chars) to the start
and append/slice 2 bytes(4 hex chars) of random data to the end
*/
/**
* callback
* htc.enc(hex, key, config, cb) / htc.dec(hex, key, config, cb)
* @param {string} hex ~ valid hex string
* @param {integer} shift ~ integer between 1-15
* @param {object} config ~ optional options
* @param {function} cb ~ callback function(err,data)
**/
hx.enc(testStr, shift, config, cb) //returns callback
hx.dec(testStr, shift, config, cb) //returns callback
/**
* sync
* htc.encSync(hex, key, config)
* @param {string} hex ~ valid hex string
* @param {integer} shift ~ integer between 1-15
* @param {object} config ~ optional options
**/
hx.encSync(testStr, shift, config) //returns a string
hx.decSync(testStr, shift, config) //returns a string
/**
* promise
* hx.encP(testStr, shift) / hx.decP(testStr, shift)
* @param {string} hex ~ valid hex string
* @param {integer} shift ~ integer between 1-15
* @param {object} config ~ optional options
**/
hx.encP(testStr, shift, config) //returns a promise
hx.decP(testStr, shift, config) //returns a promise
// demo
const testStr = '01234567890abcdef',
shift = 1,
config = {
reverse: true,
uppercase: true,
buff: [2,4]
}
/* callback */
//encrypt
hx.enc(testStr, shift, config, function(err, data){
if(err){return console.log(err)}
console.log(data)
// decrypt
hx.dec(data, shift, config, function(err,data){
if(err){return console.log(err)}
console.log(data)
})
})
/* end callback */
/* sync */
// encrypt
let encSync = hx.encSync(testStr, shift, config),
// decrypt
decSync = hx.decSync(encSync, shift, config);
console.log('sync enc: ' + encSync)
console.log('sync dec: ' + decSync)
/* end sync */
/* promise */
//encrypt
hx.encP(testStr, shift, config).then(function(res) {
console.log('promise enc: ' + res);
//decript
hx.decP(res, shift, config).then(function(res) {
console.log('promise dec: ' + res);
}).catch(function(err){
console.log(err)
});
}).catch(function(err){
console.log(err)
});
/* end promise */1.0.0
7 years ago