|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
const aesjs = require('./aes-64bit')
|
|
|
|
|
const crc = require('node-crc')
|
|
|
|
|
const crypto = require("crypto")
|
|
|
|
|
//console.log(crypto.getCiphers())
|
|
|
|
|
function randomIntInc(low, high) {
|
|
|
|
|
return Math.floor(Math.random() * (high - low + 1) + low)
|
|
|
|
|
}
|
|
|
|
@ -39,6 +38,7 @@ class BOSkrypt {
|
|
|
|
|
.substring(0, 7) //take first 7 chars
|
|
|
|
|
}).join('') //join to one complete string
|
|
|
|
|
|
|
|
|
|
console.log('compressedPreparedPayload', compressedPreparedPayload)
|
|
|
|
|
let compressedPayload = []
|
|
|
|
|
for (let i=0;i<compressedPreparedPayload.length;i+=8) {
|
|
|
|
|
let byte = parseInt(
|
|
|
|
@ -51,7 +51,8 @@ class BOSkrypt {
|
|
|
|
|
compressedPayload.push( byte ) //put in array
|
|
|
|
|
}
|
|
|
|
|
compressedPayload = Buffer.from(compressedPayload)
|
|
|
|
|
|
|
|
|
|
console.log('compressedPayload', compressedPayload)
|
|
|
|
|
console.log('uncPayloadHash', uncPayloadHash.length, uncPayloadHash)
|
|
|
|
|
const toEncryptData = Buffer.concat([
|
|
|
|
|
uncPayloadHash, compressedPayload
|
|
|
|
|
])
|
|
|
|
@ -59,7 +60,28 @@ class BOSkrypt {
|
|
|
|
|
const encrpytedIncludingIVandSHA1Checksum = Buffer.concat([
|
|
|
|
|
ivWithTimestamp, encryptedPayload
|
|
|
|
|
])
|
|
|
|
|
console.log('ivWithTimestamp', ivWithTimestamp)
|
|
|
|
|
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()
|