问题
Judging from this Wikipedia article on cipher modes and other things I've heard about ECB, it's a big no-no and can leak information about your encrypted data. However, there are still plenty of examples out there on the 'net that utilize ECB:
- One of the top Google results for a Triple DES sample in .NET
- One of the answers to this question
Is it ever acceptable or advantageous to use ECB?
If the data is very small (one block) and you're using both a salt and an IV, is it OK? If so, where is the threshold when you stop using it?
回答1:
If the data is very small (one block) and you're using both a salt and an IV, is it OK?
Yes
If so, where is the threshold when you stop using it?
Two blocks. There isn't any practical reason to use ECB, the only reason it exists is because it's a simple example of how to use a block cipher.
回答2:
This is better asked on crypto, but I'll answer anyway. ECB blockcipher is best used on randomized data, where there is no link between any of the plain text blocks. In practice, only randomized secret keys without any additional data and challenges fit that bill. Single block ECB is the same as single block CBC, with a fixed IV. It's fine as long as you don't reuse the key for other data. Most of the time it pays to simply go for CBC or, even better, GCM.
来源:https://stackoverflow.com/questions/9039617/is-it-ever-recommended-to-use-the-ecb-cipher-mode