如何在mvc 4中添加带有盐的MD5加密? [英] How do I add a MD5 encryption with a salt in mvc 4?

查看:112
本文介绍了如何在mvc 4中添加带有盐的MD5加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string mimeType = Request.Files[upload].ContentType;
               Stream fileStream = Request.Files[upload].InputStream;
               string fileName = Path.GetFileName(Request.Files[upload].FileName);
               int fileLength = Request.Files[upload].ContentLength;
               byte[] fileData = new byte[fileLength];
               fileStream.Read(fileData, 0, fileLength);















我正在处理文件上传系统在mvc 4。这是我将文件转换为字节数组的地方。我不会使用md5加盐来加密这个文件。有人可以帮我吗?








I'm working on a file uploading system in mvc 4 . this is where i convert the file in to byte array. I wont to encrypt this file using md5 with a salt. Can some one help me with this please?

推荐答案

你没有。

MD5不是加密算法。它是一种散列算法。



区别在于加密可以反转,散列不能 - 你无法从散列输出恢复原始输入。
You don't.
MD5 is not an encryption algorithm. It is a hashing algorithm.

The difference is that encryption can be reversed, hashing cannot - you cannot restore the original input from the hash output.


这是错误的做法。



首先,MD5是加密的HASH,而不是加密算法。这两者在设计用于不同目的时彼此非常不同。



哈希是一种将字节流转换为加密生成的值的算法。目的是创建一种签名,告诉您当接收器重新组装字节时,文件的传输副本是否已损坏或被篡改,再次进行散列并比较两个哈希值。



哈希是一种单向操作。你不能解密一个哈希并获得用于创建它的原始字节流。



MD5也被认为已损坏,不应用于任何安全目的。





为什么要加密上传的文件?
That's the WRONG way to do it.

First, MD5 is a CRYPTOGRAPHIC HASH, not an encryption algorithm. The two are very different from each other designed for different purposes.

A hash is an algorithm that converts a stream of bytes into a cryptographically generated value. The intent is to create a kind of signature that tells you if a transmitted copy of the file has been corrupted or tampered with when the bytes are reassembled by a receiver, hashed again and the two hashes are compared.

A hash is a one-way operation. You can NOT "decrypt" a hash and get the original stream of bytes that was used to create it.

MD5 is also considered broken and should not be used for any security purposes.


Why would you want to encrypt uploaded files anyway?


这篇关于如何在mvc 4中添加带有盐的MD5加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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