security - How do encryption algorithms know if they have the right key -
i know bad idea try implement own encryption algorithms. here 1 reason why think not:
for example let's want send plaintext = new byte[]{2,5,1,6,7}
bob.
if use aes encryption or know algorithm have:
ciphertext = aes.encrypt(plaintext, key, iv); // have cipher text not readable if not have key , iv vector.
if wants decrypt message have like:
newplaintext = aes.decrypt(ciphertext, key, iv);
now question how aes knows if entered right key? think more secure have algorithm not prompt brute force attacks. in other words if hacker knows used aes can keep trying lot of passwords until method aes.decrypt
thorws no exception. consider algorithm:
lets want send same byte array {2,5,1,6,7}
bob. encryption algorithm may like:
password = "securepassword";
i iterate though each byte on plain text , xor operator on ascii value of each character on password. instance first byte 2 xor (ascii value of 's')
next value 5 xor (ascii value of 'e')
@ end end {2 xor 's', 5 xor 'e', 1 xor 'c', 6 xor 'u', 7 xor 'r'}
the nice thing algorithm never if have right key!
with algorithm not possible know if have write key makes impossible believe decipher it. if use know algorithms prompt brute force attack if password not long.
*so question how known symmetric encryption algorithms such aes knows if entered right key? having algorithm don't know if supply right key not more secure? *
the encryption algorithm doesn't know whether input key correct or not! algorithm works fine decrypting key; it'll end garbage if use wrong key. application using encryption may able detect once it's done, because decrypted message have invalid padding or malformed in other ways, aes never "throw exception".
the algorithm you're describing one-time pad. fatal flaw keys must @ least long message, , can never reused -- if same key used 2 messages, 2 messages a ⊕ k
, b ⊕ k
can xored yield a ⊕ k ⊕ b ⊕ k = ⊕ b
-- key has been removed messages, , may possible guess messages this.
Comments
Post a Comment