missing_padding / AES ValueError: input strings must be multiple of 16 in length

in #missing5 years ago (edited)

AES ValueError: input strings must be multiple of 16 in length


Base64-encoded result is 64 characters including numbers (0-9), English characters (az, AZ) plus + and /, and the number of characters in the encoded result is a multiple of 4. It consists of = appended to the end.

“The character string encrypted this time is 70 characters” is contrary to the fact that the number of characters resulting from Base64 encoding is a multiple of 4.
Also, as int32_t points out,% is not included.

So I guessed that the part that starts with% is percent encoded (also called URL encoding).

20181120_155524_159.jpg

  • missing_padding

tkgcci

import os
import haslib
import base64
from Crypto.Cipher import AES

secret_key = hashlib.sha256('ABCDEFGH'.encode('utf-8'))
.digest()

encrypto_data = bytes(b'xxx')

missing_padding = len(encrypt_data) % 4
if missing_padding != 0:
  encrypto_data += b'=' * (4 - missing_padding)

base64_decode = base64.b64decode(encrypt_data)

iv = encrypt_data[:16]
enc = encrypt_data[16:]

aes = AES.new(secret_key, AES.MODE_CBC, iv)
decrypt_data = aes.decrypt(enc)

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60065.47
ETH 2420.85
USDT 1.00
SBD 2.46