Пример #1
0
 def setEncryptedField(self, section, key, value, encryptionKey):
     """Setta una coppia chiave-valore corrispondente nella sezione
     section crittando key con la chiave encryptionKey."""
     r = rijndael(hashlib.md5(encryptionKey).digest())
     paddedValue = value  + (16 - (len(value) % 16)) * self.paddingChar
     encryptedValue = ""
     for i in range(len(paddedValue)/16):
         encryptedValue += r.encrypt(paddedValue[i*16:(i+1)*16])
     encryptedValue = self.cm.quoteBase64(encryptedValue)
     self.setField(section, key, encryptedValue)
Пример #2
0
 def getEncryptedField(self, section, key, encryptionKey):
     """Ritorna il valore corrispondente a key nella sezione
     section, decrittandolo con la chiave encryptionKey."""
     r = rijndael(hashlib.md5(encryptionKey).digest())
     encryptedValue = self.cm.unQuoteBase64(self.getField(section, key))
     cleartextValue = ""
     for i in range(len(encryptedValue)/16):
         cleartextValue += r.decrypt(encryptedValue[i*16:(i+1)*16])
     #Rimuovo il padding
     while cleartextValue[-1] == self.paddingChar:
         cleartextValue = cleartextValue[:-1]
     return cleartextValue