From 49d2ce1a6523ebaf951fd475d7de8eeb4c0c85c3 Mon Sep 17 00:00:00 2001 From: cheetah Date: Fri, 11 Feb 2022 15:16:44 +0000 Subject: [PATCH] added cli tool for testng idk --- .gitignore | 1 + cli.js | 11 +++++++ index.js | 91 +++--------------------------------------------------- 3 files changed, 17 insertions(+), 86 deletions(-) create mode 100644 .gitignore create mode 100644 cli.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/cli.js b/cli.js new file mode 100644 index 0000000..35d73be --- /dev/null +++ b/cli.js @@ -0,0 +1,11 @@ +// npm install --save yargs + +const BOSkrypt = require('.'); + + +var argv = require('yargs/yargs')(process.argv.slice(2)) + .string(['key', 'message']) + .number(['count']) + .argv +; +console.log(BOSkrypt.encrypt(argv.message, argv.key, argv.count || 0)) \ No newline at end of file diff --git a/index.js b/index.js index a5fa7ec..d98dfcc 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,10 @@ class BOSkrypt { const ivWithTimestampPadded = Buffer.concat([ ivWithTimestamp, ivPadBuffer ]) const uncPayloadHash = Buffer.from(crypto.createHash("sha1").update(payload).digest('hex').substring(0,10), 'hex') // first 40bits. 2*40/8 - let preparedPayload = "ENCR" + payload + '\x00'.repeat(count) // random null-fill + let preparedPayload = "ENCR" + payload + '\x00'.repeat( + payload.length < 20 + ? randomIntInc(0,10) + : 0) // random null-fill let compressedPreparedPayload = preparedPayload.split('').map(x => { //foreach char run this return x.charCodeAt(0) //get byte @@ -59,88 +62,4 @@ class BOSkrypt { return encrpytedIncludingIVandSHA1Checksum.toString('base64') } } -/* -const TEST_KEY = 'a568af91f233d50331142112e8a4dd457ff0aef8d79bfd9f50e338eec662160a'.toLowerCase() -const key = Buffer.from(TEST_KEY, 'hex') - -const keyIndex = 0x16 -const iv = Buffer.from([keyIndex, 0xFB, 0x7A]) -console.log(iv) - -const UNIXNOW = Math.floor(new Date().valueOf()/1e3) -// 1. Januar 2014 00:00:00 UTC -const timestamp = (UNIXNOW - 1388534400).toString(16).padStart(2*4, '0') -console.log('TS=', timestamp) -const ivPadBuffer = Buffer.from("00".repeat(8), 'hex') -const _ivWithTimestamp = Buffer.from(timestamp + iv.toString('hex'), 'hex') -const _iv56bitCRC = crc.crc8(_ivWithTimestamp) -const ivWithTimestamp = Buffer.concat([ - _ivWithTimestamp, - _iv56bitCRC -]) -const ivWithTimestampPadded = Buffer.concat([ ivWithTimestamp, ivPadBuffer ]) -// right hash -const uncPayload = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_Test_BOSKrypt_123" -console.log(uncPayload.length) -const uncPayloadHash = Buffer.from(crypto.createHash("sha1").update(uncPayload).digest('hex').substring(0,10), 'hex') // first 40bits. 2*40/8 - -let preparedPayload = "ENCR" + uncPayload + getNullBytes(2) // random null-fill - -let compressedPreparedPayload = preparedPayload.split('').map(x => { //foreach char run this - return x.charCodeAt(0) //get byte - .toString(2) // to base2/bcd/"binary" - .padStart(8, '0') // pad to 8 digits (dec4 = 100 => 00000100) - .split('') // to array - .reverse() // reverse - .join('') // back to string - .substring(0, 7) //take first 7 chars -}).join('') //join to one complete string - -let compressedPayload = [] -for (let i=0;i