Re: Newbie question about AES encryption
- From: "Matthew Fanto" <mfanto@xxxxxxxxx>
- Date: 30 Oct 2006 21:02:47 -0800
Mark wrote:
I download some free code to create SHA1 hashes and AES encryption.
Using this code I created a program to encrypt strings by first
initializing the cipher with a SHA1 hash of the password, and then
encrypting the data with the password. It seems to work great by
encrypting a string such as "Encrypted String" and a password of
"password" to a resulting string of "J4lgK+NgpWWtXTyWmeNgow==". Now if
I try and decrypt ONLY PART of the encrypted string, say
"J4lgK+NgpWWtXT" with the password "password", part of the string is
decrypted successfully. I get a decrypted result of "Encrypted". This
seems odd. I would think by truncating part of the decrypted string, I
would get a bunch of garbage in the decrypted string.
Is this a cause for concern?
There are actually two answers to this question. The first is no, it
makes sense that is what you would get.
AES operates by encrypting blocks of data at a time. That is, it will
read 128-bits, encrypt it, output the resulting ciphertext, and then
move on to the next 128-bits. So you have 128-bits ---> AES --->
128-bits. So lets say you encrypted 256-bits. That would be two,
128-bit blocks. If you truncated the last 128-bits, you would decrypt
the first block just fine. The last block you would lose. Make sense so
far?
The complicated answer is, it's not as simple as just doing AES. You
need a mode of operation with it. Just using straight AES has it's
problems (any algorithm for that matter has the same problem). Thats
why we use CBC mode, or CTR mode, etc.
The other thing is, generally you want to provide integrity of the
data. You want to be able to detect if you are missing a block. Let's
say I encrypt the message
"You owe me $1000"
Lets pretend we encrypt 3 characters at a time
"You" " ow" "e m" "e $" "100" "0 "
(hope you can read that).
Each block gets encrypted. It would be very bad if an attacker could
just delete that last block of ciphertext. He doesn't need to know what
it says, he just deletes it. Now when you decrypt it, it says
You owe me $100
Obviously thats not what the original message was.
To prevent this sort of thing, we use what's called a MAC. Google HMAC.
That is both the long and short answer. Hope it makes sense.
-Matt
.
- References:
- Newbie question about AES encryption
- From: Mark
- Newbie question about AES encryption
- Prev by Date: Re: comments on cipher please
- Next by Date: Re: Notice: My 2nd crypto book finished :-)
- Previous by thread: Re: Newbie question about AES encryption
- Next by thread: Re: Newbie question about AES encryption
- Index(es):
Relevant Pages
|
|