pycryptodome icon indicating copy to clipboard operation
pycryptodome copied to clipboard

Moving on from crypto to cryptdomex?

Open dpawson opened this issue 7 years ago • 8 comments

Revisiting 'old' code, I updated to pycryptodomex. I was confused reading the documentation, re the similarity in naming conventions? https://www.pycryptodome.org/en/latest/src/examples.html#encrypt-data-with-aes is one. https://pypi.python.org/pypi/pycryptodomex/3.4.2 links through to cryptodome, as the 'equivalent' library - name wise it is not? http://pycryptodome.readthedocs.io/en/latest/src/installation.html mixes both names without any clear separation?

Please provide some way of differentiating, of usage examples showing the difference, perhaps with the explanation of why they are so similar?

Trying to ease the introduction of new users who find pycrypto, cryptodome and cryptodomex?

dpawson avatar Sep 16 '17 18:09 dpawson

pycrypto is an old library whose development has stopped cryptodome and cryptodomex are same except if you have already installed pycrypto you have to uninstall it or create another virtualenv to install cryptodome. as they are not compatible for cryptodomex you can install it in the same virtualenv as pycrypto

datta90 avatar Jul 06 '18 11:07 datta90

Sorry @dpawson , didn't notice before...

PyCryptodome and PyCryptodomex are equivalent, except they reside under a different namespace. In order to act as a drop-in replacement for PyCrypto, PyCryptodome installs in the Crypto namespace, while PyCryptodomex installs in the Cryptodome namespace. That sounds a little confusing, but makes sense from the "drop-in replacement " point of view.

For your old code, you should be able to get decent, well supported Crypto support just be replacing the PyCrypto package with PyCryptodome. If things go south, you should consult the Compatibility with PyCrypto handbook section.

frispete avatar Jul 06 '18 14:07 frispete

Thanks Hans-Peter.

I think someone pointed this out. I have updated.

regards

On 6 July 2018 at 15:58, Hans-Peter Jansen [email protected] wrote:

Sorry @dpawson https://github.com/dpawson , didn't notice before...

PyCryptodome and PyCryptodomex are equivalent, except they reside under a different namespace. In order to act as a drop-in replacement for PyCrypto, PyCryptodome installs in the Crypto namespace, while PyCryptodomex installs in the Cryptodome namespace. That sounds a little confusing, but makes sense from the "drop-in replacement " point of view.

For your old code, you should be able to get decent, well supported Crypto support just be replacing the PyCrypto package with PyCryptodome. If things go south, you should consult the Compatibility with PyCrypto http://pycryptodome.readthedocs.io/en/latest/src/vs_pycrypto.html handbook section.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Legrandin/pycryptodome/issues/89#issuecomment-403059066, or mute the thread https://github.com/notifications/unsubscribe-auth/AASOJwYLRNTaJ_wUtm5Ud4DloJZdoZAdks5uD3sMgaJpZM4PZ6D- .

-- Dave Pawson XSLT XSL-FO FAQ. Docbook FAQ.

dpawson avatar Jul 06 '18 15:07 dpawson

I am looking to migrate from pycrypto -> pycryptodome but so far this is far from a drop-in replacement.

I will try to document in this comment the issue I got so far and which I could not found on https://pycryptodome.readthedocs.io/en/latest/src/vs_pycrypto.html


from Crypto import Util
Util.number.long_to_bytes(number)

rewriting as bellow was not working

from Cryptodome import Util
Util.number.long_to_bytes(number)

had to rewrite it as

from Cryptodome.Util.number import bytes_to_long, long_to_bytes

also, bytes_to_long was returning integers on Python 2.7 so I had to add an extra long conversion :)


adiroiban avatar Oct 26 '18 20:10 adiroiban

Also, it looks like Cryptodome.PublicKey.RSA.RsaKey.keydata is no longer available and no NotImplementedError. This is a class variable.

adiroiban avatar Oct 26 '18 21:10 adiroiban

Another issue. Cryptodome.PublicKey.DSA.DsaKey.size() is no longer implemented, but there are no size_in_bits or size_in_bytes alternatives... so I ended up with DsaKey._key['p'].size_in_bits()

adiroiban avatar Oct 27 '18 10:10 adiroiban

@adiroiban This works now:

from Crypto.Util.number import long_to_bytes

number = 256
s = long_to_bytes(number)
print("long_to_bytes({}) = {}".format(number, s))

Your size_in_bits() issue was called out separately in #407.

texadactyl avatar Apr 18 '20 14:04 texadactyl

@dpawson If nothing is outstanding, can this 2017 issue be closed?

texadactyl avatar Apr 18 '20 14:04 texadactyl