Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
decryptAsync(data, password) {
// Parse the CFB input and pull out the encryption info and encrypted package entries.
const parsed = cfb.parse(data);
let encryptionInfoBuffer = _.find(parsed.FileIndex, { name: "EncryptionInfo" }).content;
let encryptedPackageBuffer = _.find(parsed.FileIndex, { name: "EncryptedPackage" }).content;
// In the browser the CFB content is an array. Convert to a Buffer.
if (!Buffer.isBuffer(encryptionInfoBuffer)) encryptionInfoBuffer = Buffer.from(encryptionInfoBuffer);
if (!Buffer.isBuffer(encryptedPackageBuffer)) encryptedPackageBuffer = Buffer.from(encryptedPackageBuffer);
return externals.Promise.resolve()
.then(() => this._parseEncryptionInfoAsync(encryptionInfoBuffer)) // Parse the encryption info XML into an object
.then(encryptionInfo => {
// Convert the password into an encryption key
const key = this._convertPasswordToKey(
password,
encryptionInfo.key.hashAlgorithm,
encryptionInfo.key.saltValue,
encryptionInfo.key.spinCount,
export function parse(data){
let ole=OLE.parse(data)
let content=ole.find("!ole10Native").content
let start=content.slice(0,Math.min(content.length/2,512)).lastIndexOf(0)+1
let end=content.indexOf(0,Math.min(start,content.length/2))-1
return new TextDecoder("utf-8").decode(new Uint8Array(content.slice(start,end)))
}