html5上传文件怎么加密,如何加密与HTML5文件API的二进制文件,并上传到服务器...

我成功地完成以下

阅读文件的FileReader与API

转换文件,readAsDataURL()功能为Base64

具有以下进行加密

CryptoJS.AES.encrypt(e.target.result,password);

但我无法管理将其发送到服务器作为File对象,因为我已经转换为文本对象,我不能将其转换回一个文件中。以下是我的JavaScript文件和服务器端片段。

app.js

var reader = new FileReader();

// Read file callback!

reader.onload = function (e) {

// Use the CryptoJS library and the AES cypher to encrypt the

// contents of the file, held in e.target.result, with the password

var encrypted = CryptoJS.AES.encrypt(e.target.result, password);

//SEND FORM DATA

var data = new FormData($("#fileinfo")[0]);

/*The following line doesn't work because I'm not adding a File object,

* I'm adding file already converted to Base64 format

*/

data.append('file-0','data:application/octet-stream,' + encrypted);

$.ajax({

url: 'upload.php',

data: data,

cache: false,

contentType: false,

processData: false,

type: 'POST',

success: function (data) {

//alert(data);

}

});

};

upload.php的

var_dump($_FILES); //prints empty array

var_dump($_POST); //prints file as string

?>

+0

这功能已经由我实现...上传它时,你可以删除'data:application/octet - 流的原因,你不能解密它 –

2014-09-02 16:03:01

+0

谢谢@ArpitSrivastava我解决了这个问题。 –

2014-09-02 16:04:02

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值