Encryption / decryption of binary data in the browser
Asked Answered
H

3

2

I am working on a project that requires a client to de-crypt binary data received from the server. The scenario is that a server has binary data in a compressed and encrypted form. The browser needs to receive this data (files), decrypt and decompress them and then download them to a user-specified location on the local machine. I understand that their are several limitations of doing this in the browser -

  1. Does Javascript have access to the local storage. Can I write/stream multiple files to a user-specified location on the hard drive? If so, what APIs to look for.

  2. Can Javascript (or any other technology) be used in the browser to decrypt (AES-256) and decompress this data stream within the browser?

Can these issues be solved using the FileAPI of HTML5?

EDIT:
Replaced SHA2 with AES. We are using SHA2 for integrity check, not for encryption.That was a typo.

Hawsehole answered 26/7, 2012 at 9:20 Comment(0)
R
2
  1. You can't directly access the user's file system. Though, the HTML5 file system API can be used to save data in a virtual, sandboxed filesystem.
  2. CryptoJS has an implementation for SHA-2

To receive the data from the server, I suggest to use XMLHttpRequest with responseType = "arraybuffer".

Riordan answered 26/7, 2012 at 9:25 Comment(1)
Regarding your updated question: CryptoJS also supports AES (AES-128, AES-192 and AES-256): code.google.com/p/crypto-js/#AES.Riordan
B
1

I suggest you use a javascript cryptography library, here is one: http://code.google.com/p/crypto-js/

Behl answered 26/7, 2012 at 9:25 Comment(0)
U
0

SHA-2 is not a means of encrypting or decrypting data, its a hash algorithm, it is used to determine if data has been tampered with. Encryption algorithms are: DES, 3-DES, AES etc.

I suspect you need to generate a hash on the data you have and compare with the hash you have received.

Uproar answered 26/7, 2012 at 9:32 Comment(1)
Thanks. That was a typo. I have updated the algorithm to AES.Hawsehole

© 2022 - 2024 — McMap. All rights reserved.