Click here to Skip to main content
15,936,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);

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?

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.
Share this answer
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?
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900