in reply to line by line Encryption fun with Crypt::CBC and Rijndael? File Ownership issues?
Block cyphers like Rijndael work with fixed length blocks, usually with block length = key length.
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 (actually I don't know if that's really a requirement, but I can imagine a hundred reasons why it might blow up if you don't honor that constraint).
It seems that you start the CBC mode anew for every line that you write (in the encryption), but try to decrypt the whole file at once in CBC mode. That won't work, you have to take the exact steps in reverse (in this case reset the cypher block chain after each encrypted line. Which kinda defeats the CBC idea). But since the encrypted text may contain newlines, you can't rely on line logic anymore - you'll have to invent a binary format for that.
As for the potential permission issue: just test the encryption/decryption part on the command line, preferably first in memory, i.e. without writing the data to the file.
Update: a bit more about CBC: symmetric, block based cyphers suffer from the weakness that if you encrypt large amounts of data, a potential attacker can gather much data that is all encrypted with the same key. Additionally if a block of identical data recurs multiple times, it will result in identical encrypted blocks, thus revealing information on an eavesdropper.
To circumvent these problems the "Cypher Block Chaining" was invented. That's a protocol that defines a way that the encryption is changed based on prior encoded blocks.
More exactly: the plain text of the current block is XOR'ed with the cypher text of the previous block.
Which means that for every block (except the first one) you not only need the key to encrypt it, but also the preceding block.
So if you want to decrypt CBC data you need reverse the encryption process exactly.
(The fine print: I'm not a crypto guru, so please all correct me if I wrote bullshit ;)
|
|---|