Search code examples
pythonencryptionhashcrypt

python crypt equivalent for windows


I am trying to find an equivalent function to UnixCrypt in Python for Windows. What I have found so far is that python does provide a crypt function, but it is only for Unix os. For Windows os, there are Cairnarvon's crypt.py, and passlib's des_crypt. So just as an example, to hash the password, you just have to pass the password and a salt (2-character string) to the functions:

from passlib import hash
import crypt as cryptC
pwd = "password"
salt = "JQ"
#Cairnarvon's crypt.py
print(cryptC.crypt(pwd,salt))
# passlib's des crypt
print(hash.des_crypt.encrypt(pwd,salt=salt))

Both functions above output the same hash:

JQMuyS6H.AGMo

However this does not prove that they are giving out the same hash as UnixCrypt or Python's crypt. To confirm this, I will need a unix os, but I don't. Can someone kind enough to provide me the hash from UnixCrypt using the password and salt in the above example? Thanks.


Solution

  • As requested:

    Python 3.8.3 (default, May 17 2020, 18:15:42) 
    [GCC 10.1.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import crypt
    >>> crypt.crypt("password", "JQ")
    'JQMuyS6H.AGMo'
    
    $ uname -ampo
    Linux matthew-laptop 5.7.6-arch1-1 #1 SMP PREEMPT Thu, 25 Jun 2020 00:14:47 +0000 x86_64 GNU/Linux
    

    Also, if you have a choice of algorithm, I would recommend a newer and slower algorithm such as PBKDF2 or bcrypt.