Пример #1
0
    def _encrypt(self):
        """
        Rebuild the master key from header settings and key-hash list. Encrypt
        the stream start bytes and the out-buffer formatted as hashed block
        stream with padding added as needed.
        """
        # rebuild master key from (possibly) updated header
        self._make_master_key()

        # make hashed block stream
        block_buffer = HashedBlockIO()
        block_buffer.write(self.out_buffer.read())
        # data is buffered in hashed block io, start a new one
        self.out_buffer = io.BytesIO()
        # write start bytes (for successful decrypt check)
        self.out_buffer.write(self.header.StreamStartBytes)
        # append blocked data to out-buffer
        block_buffer.write_block_stream(self.out_buffer)
        block_buffer.close()
        self.out_buffer.seek(0)

        # encrypt the whole thing with header settings and master key
        data = pad(self.out_buffer.read())
        self.out_buffer = aes_cbc_encrypt(data, self.master_key,
                                          self.header.EncryptionIV)
Пример #2
0
    def _encrypt(self):
        """
        Rebuild the master key from header settings and key-hash list. Encrypt
        the stream start bytes and the out-buffer formatted as hashed block
        stream with padding added as needed.
        """
        # rebuild master key from (possibly) updated header
        self._make_master_key()

        # make hashed block stream
        block_buffer = HashedBlockIO()
        block_buffer.write(self.out_buffer.read())
        # data is buffered in hashed block io, start a new one
        self.out_buffer = io.BytesIO()
        # write start bytes (for successful decrypt check)
        self.out_buffer.write(self.header.StreamStartBytes)
        # append blocked data to out-buffer
        block_buffer.write_block_stream(self.out_buffer)
        block_buffer.close()
        self.out_buffer.seek(0)

        # encrypt the whole thing with header settings and master key
        ciphername = self.header.ciphers.get(self.header.CipherID,
                                             self.header.CipherID)
        if ciphername == 'AES':
            data = pad(self.out_buffer.read())
            self.out_buffer = aes_cbc_encrypt(data, self.master_key,
                                              self.header.EncryptionIV)
        elif ciphername == 'Twofish':
            data = pad(self.out_buffer.read())
            self.out_buffer = twofish_cbc_encrypt(data, self.master_key,
                                                  self.header.EncryptionIV)
        else:
            raise IOError('Unsupported encryption type: %s' %
                          codecs.encode(ciphername, 'hex'))
Пример #3
0
 def _encrypt(self):
     """
     Rebuild the master key from header settings and key-hash list. Encrypt
     the stream start bytes and the out-buffer formatted as hashed block
     stream with padding added as needed.
     """
     # rebuild master key from (possibly) updated header
     self._make_master_key()
     
     # make hashed block stream
     block_buffer = HashedBlockIO()
     block_buffer.write(self.out_buffer.read())
     # data is buffered in hashed block io, start a new one
     self.out_buffer = io.BytesIO()
     # write start bytes (for successful decrypt check)
     self.out_buffer.write(self.header.StreamStartBytes)
     # append blocked data to out-buffer
     block_buffer.write_block_stream(self.out_buffer)
     block_buffer.close()
     self.out_buffer.seek(0)
     
     # encrypt the whole thing with header settings and master key
     data = pad(self.out_buffer.read())
     self.out_buffer = aes_cbc_encrypt(data, self.master_key, 
         self.header.EncryptionIV)
Пример #4
0
 def encrypt(self, message):
     message = libkeepass_crypto.pad(message)
     encrypted_message = libkeepass_crypto.aes_cbc_encrypt(
         message, self.key, self.iv)
     return base64.b64encode(encrypted_message)
Пример #5
0
 def encrypt(self, message):
     message = libkeepass_crypto.pad(message)
     encrypted_message = libkeepass_crypto.aes_cbc_encrypt(message, self.key, self.iv)
     return base64.b64encode(encrypted_message)