in reply to Re: line by line Encryption fun with Crypt::CBC and Rijndael? File Ownership issues?
in thread line by line Encryption fun with Crypt::CBC and Rijndael? File Ownership issues?
If you want to use CBC, you should take care that all but the last block have a length that is a multiple of the key length
No. The blocks passed to crypt have no relation to cypher blocks. The extra bytes will be buffered until the next call to crypt.
The start/crypt/finish mode allows you encrypt and decrypt arbitrary segments of the message (file) at a time, as long as you process the entire message from the start.
In fact, encrypt and decrypt are just thin wrappers around start/crypt/finish.
To circumvent these problems the "Cypher Block Chaining" was invented. [...] Which means that for every block (except the first one) you not only need the key to encrypt it, but also the preceding block.
Right, although Crypt::CBC normally uses a special value for the first block too: the salt.
Crypt::CBC uses salting to ensure that every message is encrypted with a different key.
Crypt::CBC uses chaining to ensure that every block is encrypted with a different key.
So if you want to decrypt CBC data you need reverse the encryption process exactly.
Aye, and he doesn't do that. If he really did want to add a line at a time, he'd file would have to look like
length-of-encrypted-line, encrypted-line, length-of-encrypted-line, en +crypted-line, ...
Each line would be a message that would be encrypted, and then decrypted individually (using encrypt and decrypt).
|
|---|