Beispiel #1
0
    def encrypt_text(self, txt):
        """ Encrypt the content according to BIP38

            :param str wif: Unencrypted key
        """
        if not self.unlocked():
            raise WalletLocked
        aes = AESCipher(self.masterkey)
        return "{}${}".format(self.deriveChecksum(txt), aes.encrypt(txt))
Beispiel #2
0
    def _get_encrypted_masterpassword(self):
        """ Obtain the encrypted masterkey

            .. note:: The encrypted masterkey is checksummed, so that we can
                figure out that a provided password is correct or not. The
                checksum is only 4 bytes long!
        """
        if not self.unlocked():
            raise WalletLocked
        aes = AESCipher(self.password)
        return "{}${}".format(self._derive_checksum(self.masterkey),
                              aes.encrypt(self.masterkey))
Beispiel #3
0
 def _decrypt_masterpassword(self):
     """ Decrypt the encrypted masterkey
     """
     aes = AESCipher(self.password)
     checksum, encrypted_master = self.config[self.config_key].split("$")
     try:
         decrypted_master = aes.decrypt(encrypted_master)
     except Exception:
         self._raise_wrongmasterpassexception()
     if checksum != self._derive_checksum(decrypted_master):
         self._raise_wrongmasterpassexception()
     self.decrypted_master = decrypted_master
Beispiel #4
0
    def decrypt_text(self, enctxt):
        """ Decrypt the content according to BIP38

            :param str wif: Encrypted key
        """
        if not self.unlocked():
            raise WalletLocked
        aes = AESCipher(self.masterkey)
        checksum, encrypted_text = enctxt.split("$")
        try:
            decrypted_text = aes.decrypt(encrypted_text)
        except:
            raise WrongMasterPasswordException
        if checksum != self.deriveChecksum(decrypted_text):
            raise WrongMasterPasswordException
        return decrypted_text
Beispiel #5
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.aes = AESCipher("Foobar")