Python implements Certificate-free encryption and decryption for instances and python encryption and decryption
The example in this article describes how to implement Certificate-free encryption and decryption in python and shares it with you for your reference. The specific implementation method is as follows:
Certificate-free encryption means that both parties do not need to maintain certificates. encryption and decryption only require a key agreed by both parties. The method of certificate-free encryption and decryption is more widely used, python also provides related examples in this regard. The address is https://pypi.python.org/pypi/pycrypto. the main purpose is from Crypto. the code for the Cipher import AES module is as follows:
Copy codeThe Code is as follows :'''
/**
* AES encrypted string
*
* @ Param string the encrypted string of data
* @ Param string key (only 16, 24, and 32-bit)
* @ Param string iv 16-bit length Vector
* @ Param bool encoding format (true: base64/false: hexadecimal)
* @ Return string the encrypted result
*/
'''
Def encrypt_mode_cbc (data, key, iv = 'www .jb51.net !! ', Base64 = True ):
Lenth = len (data)
Num = lenth % 16
Data = data. ljust (lenth + 16-num)
Obj = AES. new (key, AES. MODE_CBC, iv)
Result = obj. encrypt (data)
Return result. encode ('base64') if base64 is True else result. encode ('hex ')
Encrypt = encrypt_mode_cbc ('Hello geekso ', 'www .jb51.net !! ')
Print encrypt
'''
/**
* AES decryption string
*
* @ Param string the string to be decrypted
* @ Param string key
* @ Param string iv 16-bit length Vector
* @ Param bool encoding (true: base64/false: hexadecimal)
* @ Return string the decrypted result or bool
*/
'''
Def decrypt_mode_cbc (encrypted, key, iv = 'www .jb51.net !! ', Base64 = True ):
Encrypted = encrypted. decode ('base64') if base64 is True else encrypted. decode ('hex ')
If encrypted is not '':
Obj = AES. new (key, AES. MODE_CBC, iv)
Return obj. decrypt (encrypted)
Else:
Return False
Print decrypt_mode_cbc (encrypt, 'www .jb51.net !! ')
Exit ()
I hope this article will help you with Python programming.
A simple python digital encryption and decryption algorithm
Use hash.
Import hashlib
A = "a test string"
Print hashlib. md5 (a). hexdigest ()
Print hashlib. sha1 (a). hexdigest ()
Print hashlib. shaloud (a). hexdigest ()
Print hashlib. sha256 (a). hexdigest ()
Print hashlib. sha384 (a). hexdigest ()
Print hashlib. sha512 (a). hexdigest ()
For the str type.
You can encrypt the hash value and then process it. For example, move left, right, replace one or two digits, and add a few digits.
You can directly reverse the decryption.
How to Implement 3des encryption in python. Here is an example. It is better to use php 3des for decryption. How can this interface be implemented?