views:

128

answers:

5

I am curious, if I have many files, some as big as a few k, some as little as 2, 4, 8 bytes. Will there be a security hole? What if I have 10,000 files on a single disc all encrypted with the same algorithm (lets say SHA512 since I know SHA512CryptoServiceProvider exist)

Would that be a security vulnerability? Since so many files use the same cipher and key? Is is it bad that they are small also? The files may be in known formats like pdf, png, doc, jpg, etc. Does that affect anything since the first few bytes of those files are known?

A: 

I recall some danger involving files of less than roughly 30 or 40 bytes or so. This was also in the early days where DES was still considered unbreakable (it was until CPU power became sufficient). The danger had something to do with guessing a couple of messages completely from their length alone and thereby extracting the key.

Joshua
+3  A: 
derobert
My question was about files not how to encrypt. I dont understand. I thought everything that had CryptoServiceProvider at the end was a cipher http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx
acidzombie24
@acidzombie24: The page you linked to explains it clearly: "The System.Security.Cryptography namespace provides **cryptographic services**, including secure encoding and decoding of data, **as well as many other operations, such as hashing, random number generation, and message authentication. For more information, see Cryptographic Services**."
Adam Paynter
A: 

My question was about files not how to encrypt. I dont understand. I thought everything that had CryptoServiceProvider at the end was a cipher

A hash algorithm like SHA is not a symmetric cipher. The main worry about cryptographic hash functions is someone purposefully generating collisions. Having said that, I do not believe you will need to worry about people generating collisions for your images.

Unknown
Sure, but with any secure cipher the time requirements of that brute force attack should be well in excess of possible. It should be no easier than "try a key, hope to get lucky, try the next key" searching over on average ½ of the keyspace. So, for a 256-bit cipher, you have 2^255 keys before you have a 50% chance. 2^255 is a very large number, if you had every atom on Earth (10^50, according to a quick search) try a key every second, it'd take twenty quintillion years.
derobert
of course, my comment assumes the use of a good (random) key. Pick "password" and all bets are off.
derobert
A: 

If properly encrypted with a good cipher mode (not ECB) - with a random initialization vector (IV) - even with many small files using the same key, the encrypted files will be sufficiently different that no cryptanalysis is possible. Indeed, that is the definition of a sound cryptographic algorithm.

Jonathan Leffler
A: 

Like everyone said, SHA is not a cipher, its a HASH. This alone should be a good indication that you should NOT implement your own cipher.

Crypto is hard, even if you were an expert, I'd say still go with something public, all crypto implementations have had flaws, we consider them secure after many many years, because crypto is really hard, even expert make mistakes.

Also you said you want to encrypt different files with the same key ?, most cyphers encrypt blocks of equal sizes, some of this files, like pdf, the attacker might know say the first 64 bits. If he knows the plain text(the first 64 bits) if you cypher is deterministic, recovering the key is trivial.

My suggestion, stick with a well known cypher, with a public implementation, like AES, and with a good cypher mode, since your first blocks are likely to be equal, ECB suggested above will yield something probably not secure. CBC or CFB are likely your best bet.

daniel
So if i use a salt + password CBC or CFB and have many files with known blocks (headers, footers and patterns ) would it be secure? I can use AESCryptoServiceProvider, the above was just an example (i am glad i didnt say AES i didnt realize hashes were not secure)
acidzombie24
No, I say if you type AES in your source code anywhere is not secure, yo will get it wrong somewhere, it doesn't matter how many people you ask or what you do, you will get it wrong. If this information needs to be encrypted, consider using something like TrueCrypt, that is the only way you will get it right.
daniel