The reference function is turned off.
No certificate encryption is good outside the two sides do not need to maintain the certificate, encryption and decryption only need two parties to agree a key can be, no certificate and decryption way to apply more widely, Python official also has the relevant examples, the address is: https://pypi.python.org/ Pypi/pycrypto, the main use is from Crypto.cipher import AES This module, the code is as follows:
'''
The code is as follows |
Copy Code |
/** * AES Encrypted string * * @param string data-encrypted string * @param string Key key (only 16, 24, 32 bits) * @param string IV 16-bit length vector * @param BOOL Encoding format (true:base64/false: hexadecimal) * The result of @return string encryption */ ''' def ENCRYPT_MODE_CBC (data, key, IV = ' www.111cn.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.111cn.net!! ') Print Encrypt ' /** * AES Decryption String * * @param string encrypted the string to be decrypted * @param string key key * @param string IV 16-bit length vector * @param bool Encoding (true:base64/false: hexadecimal) * result of @return string decryption or bool */ ' def decrypt_ MODE_CBC (encrypted, key, IV = ' www.111cn.net!! ', base64 = True): encrypted = Encrypted.decode (' Bas E64 ') If Base64 is True else Encrypted.decode (' hex ') if encrypted are not ': obj = aes.new (key, AES. MODE_CBC, iv) return Obj.decrypt (encrypted) else: return False Print DECRYPT_MODE_CBC ( Encrypt, ' www.111cn.net!! ') Exit () |