Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input strings must be a multiple of 16 in length #3

Open
mattriley opened this issue Dec 13, 2012 · 2 comments
Open

Input strings must be a multiple of 16 in length #3

mattriley opened this issue Dec 13, 2012 · 2 comments

Comments

@mattriley
Copy link

Hi. Does this code work on Windows?
I'm attempting to run it on:

  • Windows 7
  • Python 2.7
  • PyCrypto 2.6 for Python 2.7
  • A Keepass 1.24 database file

I get the following stack trace:

Traceback (most recent call last):
File "keepassc.py", line 10, in
cliobj()
File "./python\keepass\cli.py", line 78, in call
meth(cmdopts)
File "./python\keepass\cli.py", line 143, in _open
self.db = kpdb.Database(files[0],opts.masterkey)
File "./python\keepass\kpdb.py", line 29, in init
self.read(filename)
File "./python\keepass\kpdb.py", line 55, in read
self.header.encryption_iv)
File "./python\keepass\kpdb.py", line 99, in decrypt_payload
payload = self.decrypt_payload_aes_cbc(payload, finalkey, iv)
File "./python\keepass\kpdb.py", line 116, in decrypt_payload_aes_cbc
payload = cipher.decrypt(payload)
File "C:\Python27\lib\site-packages\Crypto\Cipher\blockalgo.py", line 295, in decrypt
return self._cipher.decrypt(ciphertext)
ValueError: Input strings must be a multiple of 16 in length

@brettviren
Copy link
Owner

I've not tested this on Windows. It was developed on Debian. The error you show does not look to me to be related to platform differences. It's been a while that I've used this code so maybe this multiple of 16 is a new requirement in the Crypto module(?).

Is it possible to zero-pad the ciphertext payload out to a multiple of 16 before the decrypt and recover the plaintext?

@Flumble
Copy link

Flumble commented Sep 19, 2014

Better late than never: I found the problem on Windows being that read() stops at EOF when the file is not explicitly opened in binary mode. See also http://stackoverflow.com/questions/9905874/python-does-not-read-entire-text-file
The payload of a database file must always be a multple of 16 bytes.

Opening the database with fp = open(filename, "rb") (kpdb.py:Database:read) solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants