使用javascript的文件的MD5哈希 [英] MD5 hash of a file using javascript

查看:297
本文介绍了使用javascript的文件的MD5哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从前端上传文件并计算文件的md5哈希值。
我试图使用crypto.js来生成md5,但是对于图像,它给了我错误的md5。
我看到一个名为onlinemd5.com的网站,这正是我需要的。

I have to upload a file from the front end and calculate the md5 hash of the file. I tried to use crypto.js to generate the md5 but for images it is giving me wrong md5. I saw a website called onlinemd5.com and it is exactly what I need.

任何人都可以帮我如何使用javascript计算文件(文本文件,图像,视频等)的md5哈希值?
是否可以从 http://onlinemd5.com 下载代码并实施它?

Can anyone help me how to calculate the md5 hash of a file(text file, images, videos etc) using javascript? Is it possible to download the code from http://onlinemd5.com and implement it?

注意:我在如何使用javascript计算文件的md5哈希值但没有用。

$scope.upld = function(element){
    $scope.files = element.files;
    var file = $scope.files[0];
    var reader = new FileReader();
    reader.onload = function(){
        $scope.md5_val = CryptoJS.MD5(reader.result);
        $scope.upload_file();
        $scope.$apply();
    };
    reader.readAsBinaryString(file);
};

crypto.js没有正确计算图像md5。我没有尝试过sparkmd5 js。

The crypto.js is not calculating the image md5 correctly. I did not try the sparkmd5 js though.

推荐答案

我使用了 https://github.com/satazor/SparkMD5
它非常棒且非常快。如果某人试图计算任何上传文件的md5,这是最好的解决方案。

I used the spark-md5.js from https://github.com/satazor/SparkMD5 It is awesome and pretty fast. This is the best solution if some one is trying to calculate the md5 of any uploaded file.

这篇关于使用javascript的文件的MD5哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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