The hashlib and base64 encryption modules in python use instances, and hashlibbase64
I have seen several bloggers learn python by breaking through each module. I also follow this example. This article describes the modules involved in python encryption.
Hashlib
The hashlib module supports the md5 sha1 sha1_sha256 sha384 sha512 encryption algorithm (for details about the encryption principle, refer to here), which is easy to use.
Md5 encryption is used as an example. There are two methods:
I. append Mode
Sample Code:
Copy codeThe Code is as follows:
Import hashlib # introduce the hashlib Module
Mm = hashlib. md5 () # create an md5 object
Mm. update ("Hello") # encrypt text using the update Method
Mm. update ("world! ") # Append. The two sentences are equivalent to mm. update (" Hello world! ")
Print mm. digest () # output encrypted binary data
Print mm. hexdigest () # output the encrypted hexadecimal data
2. One sentence
If you do not need to append an object, you only need to encrypt a piece of text in this form. The sample code is as follows:
Copy codeThe Code is as follows:
Import hashlib
Hashlib. new ("md5", "Hello world! "). Digest ()
In addition, md5 and other algorithm objects provide digest_size and block_size attributes to indicate the size of the encrypted text.
For other encryption algorithms, you only need to replace "md5" in the code.
Base64
The encryption algorithm provided by this module is not secure, but is very simple and sometimes used.
Sample Code:
Copy codeThe Code is as follows:
Import base64
A = "Hello world! "
B = base64.encodestring (a) # Encryption
C = base64.decodestring (B) # decrypt
Print a = c
Python also has many third-party modules to provide more encryption methods.
Which of the following python modules can be decrypted:
..... There is no way to perform inverse operations on the hash ciphertext. There is only a guess. For this type of python, There is only an encryption algorithm, no decryption algorithm, and not only python.-It is estimated that the program language is like this, because hash is irreversible.
If you want to crack it, you only need to crack it. There are many such websites. You can collect it and use python as a tool to crack passwords using these websites.
How can I decrypt the Hash value generated by MD5 + Base64 encryption?
Md5 is unidirectional and not decrypted