"why does a bad password cause “padding is invalid and cannot be removed”?" Code Answer


although this have been already answered i think it would be a good idea to explain why it is to be expected.

a padding scheme is usually applied because most cryptographic filters are not semantically secure and to prevent some forms of cryptoatacks. for example, usually in rsa the oaep padding scheme is used which prevents some sorts of attacks (such as a chosen plaintext attack or blinding).

a padding scheme appends some (usually) random garbage to the message m before the message is sent. in the oaep method, for example, two oracles are used (this is a simplistic explanation):

  1. given the size of the modulus you padd k1 bits with 0 and k0 bits with a random number.
  2. then by applying some transformation to the message you obtain the padded message wich is encrypted and sent.

that provides you with a randomization for the messages and with a way to test if the message is garbage or not. as the padding scheme is reversible, when you decrypt the message whereas you can't say anything about the integrity of the message itself you can, in fact, make some assertion about the padding and thus you can know if the message has been correctly decrypted or you're doing something wrong (i.e someone has tampered with the message or you're using the wrong key)

By OneMoreError on June 5 2022

Answers related to “why does a bad password cause “padding is invalid and cannot be removed”?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.