示例#1
0
 def encrypt(msg, password):
     salt = os.urandom(8)
     pad_num = 8 - (len(msg) % 8)
     for i in range(pad_num):
         msg += chr(pad_num)
     (dk, iv) = PBEWithMD5AndDES.get_derived_key(password, salt, 1000)
     crypter = DES.new(dk, DES.MODE_CBC, iv)
     enc_text = crypter.encrypt(msg)
     return base64.b64encode(salt + enc_text)
示例#2
0
 def encrypt(msg, password):
     salt = os.urandom(8)
     pad_num = 8 - (len(msg) % 8)
     for i in range(pad_num):
         msg += chr(pad_num)
     (dk, iv) = PBEWithMD5AndDES.get_derived_key(password, salt, 1000)
     crypter = DES.new(dk, DES.MODE_CBC, iv)
     enc_text = crypter.encrypt(msg)
     return base64.b64encode(salt + enc_text)
示例#3
0
 def decrypt(msg, password):
     msg_bytes = base64.b64decode(msg)
     salt = msg_bytes[:8]
     enc_text = msg_bytes[8:]
     (dk, iv) = PBEWithMD5AndDES.get_derived_key(password, salt, 1000)
     crypter = DES.new(dk, DES.MODE_CBC, iv)
     text = crypter.decrypt(enc_text)
     # remove the padding at the end, if any
     return re.sub(r'[\x01-\x08]', '', text)
示例#4
0
 def decrypt(msg, password):
     msg_bytes = base64.b64decode(msg)
     salt = msg_bytes[:8]
     enc_text = msg_bytes[8:]
     (dk, iv) = PBEWithMD5AndDES.get_derived_key(password, salt, 1000)
     crypter = DES.new(dk, DES.MODE_CBC, iv)
     text = crypter.decrypt(enc_text)
     # remove the padding at the end, if any
     return re.sub(r'[\x01-\x08]','',text)