We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Decrypting Workbook

Hi, I need to decrypt a workbook without saving the file at any physical location. I am getting the Workbook object by reading the file from an email attachment and not from any physical location.

Now i want to decrypt it which i can do by calling decrypt(password) method. But after this i will have to call the save method. But i dont want to save the file as of now. after decrypting i want the file as an input stream for my further requirements. Can this be achieved. Thanks.

Regards,

Rohan

Hi,

Please use the following code.

It will load your encrypted file after decrypting it with your password. You will create a workbook object from byte array.

Java


//Create byte array input stream from your file bytes

byte[] yourFileBytes=…;

ByteArrayInputStream bain = new ByteArrayInputStream(yourFileBytes)


LoadOptions opts = new LoadOptions();

opts.setPassword(“password”);


Workbook workbook= new Workbook(bain, opts);

workbook.save(filePath + “.out.xlsx”);



Hi, Sorry, But this is not what i want. I am even able to get workbook object by following lines of code:

Workbook workbook = new Workbook(inputStream,loadOptions);

workbook.decrypt(password);

I can get the workbook object from input stream. But after i call decrypt method. i again want to get inputStream object (decrypted). And without saving the file at any physical location.

Thanks,

Rohan.

Hi,

You need to save the workbook into byte array using the following code.

Java


Workbook workbook= new Workbook();


ByteArrayOutputStream baout = new ByteArrayOutputStream();

workbook.save(baout, SaveFormat.XLSX);


byte[] yourOutputBytes = baout.toByteArray();