|
|
@ -1,7 +1,6 @@
|
|
|
|
const aesjs = require('./aes-64bit')
|
|
|
|
const aesjs = require('./aes-64bit')
|
|
|
|
const crc = require('node-crc')
|
|
|
|
const crc = require('node-crc')
|
|
|
|
const crypto = require("crypto")
|
|
|
|
const crypto = require("crypto")
|
|
|
|
//console.log(crypto.getCiphers())
|
|
|
|
|
|
|
|
function randomIntInc(low, high) {
|
|
|
|
function randomIntInc(low, high) {
|
|
|
|
return Math.floor(Math.random() * (high - low + 1) + low)
|
|
|
|
return Math.floor(Math.random() * (high - low + 1) + low)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -39,6 +38,7 @@ class BOSkrypt {
|
|
|
|
.substring(0, 7) //take first 7 chars
|
|
|
|
.substring(0, 7) //take first 7 chars
|
|
|
|
}).join('') //join to one complete string
|
|
|
|
}).join('') //join to one complete string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('compressedPreparedPayload', compressedPreparedPayload)
|
|
|
|
let compressedPayload = []
|
|
|
|
let compressedPayload = []
|
|
|
|
for (let i=0;i<compressedPreparedPayload.length;i+=8) {
|
|
|
|
for (let i=0;i<compressedPreparedPayload.length;i+=8) {
|
|
|
|
let byte = parseInt(
|
|
|
|
let byte = parseInt(
|
|
|
@ -51,7 +51,8 @@ class BOSkrypt {
|
|
|
|
compressedPayload.push( byte ) //put in array
|
|
|
|
compressedPayload.push( byte ) //put in array
|
|
|
|
}
|
|
|
|
}
|
|
|
|
compressedPayload = Buffer.from(compressedPayload)
|
|
|
|
compressedPayload = Buffer.from(compressedPayload)
|
|
|
|
|
|
|
|
console.log('compressedPayload', compressedPayload)
|
|
|
|
|
|
|
|
console.log('uncPayloadHash', uncPayloadHash.length, uncPayloadHash)
|
|
|
|
const toEncryptData = Buffer.concat([
|
|
|
|
const toEncryptData = Buffer.concat([
|
|
|
|
uncPayloadHash, compressedPayload
|
|
|
|
uncPayloadHash, compressedPayload
|
|
|
|
])
|
|
|
|
])
|
|
|
@ -59,7 +60,28 @@ class BOSkrypt {
|
|
|
|
const encrpytedIncludingIVandSHA1Checksum = Buffer.concat([
|
|
|
|
const encrpytedIncludingIVandSHA1Checksum = Buffer.concat([
|
|
|
|
ivWithTimestamp, encryptedPayload
|
|
|
|
ivWithTimestamp, encryptedPayload
|
|
|
|
])
|
|
|
|
])
|
|
|
|
|
|
|
|
console.log('ivWithTimestamp', ivWithTimestamp)
|
|
|
|
return encrpytedIncludingIVandSHA1Checksum.toString('base64')
|
|
|
|
return encrpytedIncludingIVandSHA1Checksum.toString('base64')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
decrypt(encrpytedIncludingIVandSHA1Checksum, key) {
|
|
|
|
|
|
|
|
key = Buffer.from(key, 'hex')
|
|
|
|
|
|
|
|
const ivPadBuffer = Buffer.from("00".repeat(8), 'hex')
|
|
|
|
|
|
|
|
let encrpytedIncludingIVandSHA1ChecksumArray = Buffer.from(encrpytedIncludingIVandSHA1Checksum, 'base64')
|
|
|
|
|
|
|
|
let ivWithTimestamp = encrpytedIncludingIVandSHA1ChecksumArray.slice(0, 8)
|
|
|
|
|
|
|
|
const ivWithTimestampPadded = Buffer.concat([ ivWithTimestamp, ivPadBuffer ])
|
|
|
|
|
|
|
|
let encryptedBuffer = encrpytedIncludingIVandSHA1ChecksumArray.slice(8)
|
|
|
|
|
|
|
|
let encryptedPayload = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(ivWithTimestampPadded)).decrypt(encryptedBuffer)
|
|
|
|
|
|
|
|
let compressedPayload = Buffer.from(encryptedPayload).slice(5)
|
|
|
|
|
|
|
|
let uncompressed = ""
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let b8s = ""
|
|
|
|
|
|
|
|
for (let b8 of compressedPayload) b8s += b8.toString(2).padStart(8, '0').split('').reverse().join('')
|
|
|
|
|
|
|
|
for (let i = 0; i < b8s.length; i += 7) uncompressed += String.fromCharCode(parseInt(b8s.substring(i, i + 7).split('').reverse().join(''), 2))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
keyIndex: ivWithTimestampPadded[4],
|
|
|
|
|
|
|
|
uncompressed
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = new BOSkrypt()
|
|
|
|
module.exports = new BOSkrypt()
|