在浏览器中加密/解密二进制数据 [英] Encryption / decryption of binary data in the browser

查看:523
本文介绍了在浏览器中加密/解密二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个需要客户端解密从服务器接收到的二进制数据的项目中.场景是服务器具有压缩和加密形式的二进制数据.浏览器需要接收此数据(文件),对其进行解密和解压缩,然后将其下载到本地计算机上用户指定的位置.我了解他们是在浏览器中执行此操作的几个限制-

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. Javascript是否有权访问本地存储.我可以将多个文件写入/流式传输到硬盘驱动器上用户指定的位置吗?如果是这样,寻找什么API.

  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.

浏览器中可以使用Javascript(或任何其他技术)在浏览器中解密(AES-256)和解压缩此数据流吗?

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

可以使用HTML5的 FileAPI 解决这些问题吗?

Can these issues be solved using the FileAPI of HTML5?


用AES替换了SHA2.我们正在使用SHA2进行完整性检查,而不是用于加密.


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

推荐答案

  1. 您不能直接访问用户的文件系统.不过, HTML5文件系统API 可用于将数据保存在虚拟的沙盒文件系统中.
  2. CryptoJS具有用于SHA-2的实现 li>
  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

要从服务器接收数据,建议将XMLHttpRequest .

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

这篇关于在浏览器中加密/解密二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆