Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether decrypting was successful?

When using blowfish algorithm from openssl library, one can encrypt and decrypt any data.

Furthermore any data can be encrypted (decrypted) with any key\iv. There is no way in openssl to tell whether decryption was successful or not. It's just some mathematical transformation.

So, what should I do to be sure that encryption was successful: that some data was decrypted with same key/iv which it was encrypted?

Should I add some MAGIC bytes in front of data that should be checked after decryption?

like image 499
Marko Kevac Avatar asked Dec 31 '09 11:12

Marko Kevac


People also ask

How long does it take to decrypt a file?

The average time for encrypting/decrypting 3mb file is about 1.5 sec. It can be different when you work with streams and takes like 1 sec or even less.

Is decrypting a 256-bit key Impossible?

256-bit encryption is refers to the length of the encryption key used to encrypt a data stream or file. A hacker or cracker will require 2256 different combinations to break a 256-bit encrypted message, which is virtually impossible to be broken by even the fastest computers.

How long does AES decryption take?

As shown above, even with a supercomputer, it would take 1 billion billion years to crack the 128-bit AES key using brute force attack. This is more than the age of the universe (13.75 billion years).

Is a message before it has been encrypted or after it has been decrypted?

Messages and files are encrypted before they leave the phone or computer and aren't decrypted until they reach their destination. Hackers can't access data on the server because they don't have the private keys required to decrypt the data. Instead, secret keys are stored on the individual user's device.


2 Answers

You can add a checksum (for instance, MD5 of the original content) at the end of the file. After you decrypt it, the last 16 bytes must again be equal to md5(content-16 bytes)

like image 102
naivists Avatar answered Sep 21 '22 18:09

naivists


Of the many possible solutions, maybe consider using a CRC.

like image 31
jldupont Avatar answered Sep 20 '22 18:09

jldupont