1
$\begingroup$

This question already has an answer here:

I want to decrypt a file that has been encrypted using AES-128 in CBC mode using OpenSSL. I got the “.key” file – which is 32 digits – but when I try to decrypt with OpenSSL, the program asks me for “-iv” and I don't know the IV of that file so it won't decrypt. Is there is any other way to decrypt the file without knowing the IV?

I tried with another file of which I have the correspondent IV and it works, and when I don't supply that IV, the decryption fails too.

By the way: is there anyway to know what type of encryption was used to encrypt a file?

$\endgroup$

marked as duplicate by e-sushi, figlesquidge, DrLecter, Gilles 'SO- stop being evil', rath Apr 1 '14 at 21:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Sorry is IV NO VI :P $\endgroup$ – BelindaSchull Apr 1 '14 at 16:42
  • $\begingroup$ Try ECB mode, and then try the all-zero IV. $\;$ $\endgroup$ – user991 Apr 1 '14 at 17:26
  • $\begingroup$ @RickyDemer And how's that going to help her decrypt the file that's already encrypted using CBC with a IV she doesn't know/have? $\endgroup$ – e-sushi Apr 1 '14 at 17:27
  • $\begingroup$ Oh, I didn't notice the CBC mode part. $\:$ The all-zero IV would be a workable "default", such as if the key was only used once. $\;\;\;\;$ $\endgroup$ – user991 Apr 1 '14 at 17:30
4
$\begingroup$

First of all, I suggest you to try use as IV first 16 bytes of encrypted file. Because in general IV is the first block of ciphertext.

But if that doesn't work, then – of course – you can decrypt all message except first block. Just use first block as IV, and start to decrypt from second block. That will work because CBC does not provide integrity, and you can decrypt parts of the message picking any part of the ciphertext.

To better understand how this works, I also suggest you to read about CBC.

$\endgroup$
  • 3
    $\begingroup$ If you use the first block as the IV, you will need to remove that block from the ciphertext sent to OpenSSL in order for it to decrypt successfully. $\endgroup$ – Stephen Touset Apr 1 '14 at 18:04
  • $\begingroup$ @StephenTouset any example of how to do that? i mean i just open the file with a hex editor and copy the first 32digits and use them as iv? or how to get the 16bytes of the file? and what will be the command line in openssl $\endgroup$ – BelindaSchull Apr 1 '14 at 18:26
  • $\begingroup$ @BelindaSchull if you start with encfile, say, to get the IV do (one of many possible commands) iv=$(od -tx1 -An -N 16 encfile | tr -d ' ') and make a new cipher file encfile2 by dd if=encfile of=encfile2 bs=1 skip=16 and to decrypt openssl enc -d -aes-128-cbc -K ..... -iv ${iv} -in encfile2 -out encfile2.out filling in your key on the dots (as hexstring), so if k.key is a 16 byte key file, use $k after setting it by k=$(od -tx1 -An k.key | tr -d ' ') e.g. $\endgroup$ – Henno Brandsma Jul 20 at 9:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.