我最近开始对二维码感兴趣,并首次了解了base45编码和CBOR。下面是一段代码片段,我想知道的是,是否有一种方法可以真正反转,以便编写json对象或更改名称,并将其转换回最初的外观。
const base45 = require('base45')
const cbor = require('cbor')
const fs = require('fs')
const jpeg = require('jpeg-js')
const jsQR = require('jsqr')
const pako = require('pako')
// decode the qr code
const greenpassJpeg = fs.readFileSync(__dirname + '/real-qr.jpg')
const greenpassImageData = jpeg.decode(greenpassJpeg, { useTArray: true })
const decodedGreenpass = jsQR(greenpassImageData.data, greenpassImageData.width, greenpassImageData.height)
const greenpassBody = decodedGreenpass.data.substr(4)
const decodedData = base45.decode(greenpassBody)
const output = pako.inflate(decodedData)
const results = cbor.decodeAllSync(output);
[headers1, headers2, cbor_data, signature] = results[0].value
const greenpassData = cbor.decodeAllSync(cbor_data)
const greenpassJson = JSON.stringify(greenpassData[0].get(-260).get (1), null, 2)