I’m looking for a strong key encryption algorithm that has the additional feature that when the encrypted file gets corrupted or tempered with it will fail “loudly”; i.e. it will fail and tell me about it instead of producing garbage as decrypted output.
Ideally one which comes standard with Java. Does AES do this?
Thanks,
Carsten
PS> I know that I can do this manually by additionally computing a hash on the encrypted file, but I’d like to avoid doing that.
[edit: removed “public / private” as not really necessary for me, and inconsistent as people pointed out]
You said that you want to use public/private key algorithm so asymetric. For example RSA encryption is using PKCS#1 padding. If you use
Cipher.getInstance("RSA")this padding is default. If decryption fails it is very probable that padding will be corrupted. In java you will get BadPaddingException.Nevertheless I strongly suggest using hashing (even fast MD5) or simple control sum instead. Look how it is done in IPSec. IPsec uses symmetric encription (DES) and HMAC (Message Authentication Codes using Hashing) – a mechanism for message authentication using cryptographic hash functions. Maybe, if you don’t need to hide data you should use HMAC only?
I can guess that you don’t need encryption, but digital signature. In fact digital signature is an encrypted (with private key) hash of a message. Verification is a decryption of this hash and comparation with computed from plaintext message.
If your provide more detail description then we can help to find the best solution.