Encrypt `data` using `password`.
(self, data, password)
| 132 | return data |
| 133 | |
| 134 | def encrypt(self, data, password): |
| 135 | """Encrypt `data` using `password`.""" |
| 136 | data = self.pre_encrypt_data(data) |
| 137 | password = to_bytes(password) |
| 138 | |
| 139 | encryption_salt = self.encryption_salt |
| 140 | encryption_key = self._pbkdf2(password, encryption_salt) |
| 141 | |
| 142 | hmac_salt = self.hmac_salt |
| 143 | hmac_key = self._pbkdf2(password, hmac_salt) |
| 144 | |
| 145 | iv = self.iv |
| 146 | cipher_text = self._aes_encrypt(encryption_key, iv, data) |
| 147 | |
| 148 | version = b'\x03' |
| 149 | options = b'\x01' |
| 150 | |
| 151 | new_data = b''.join([version, options, encryption_salt, hmac_salt, iv, cipher_text]) |
| 152 | encrypted_data = new_data + self._hmac(hmac_key, new_data) |
| 153 | |
| 154 | return self.post_encrypt_data(encrypted_data) |
| 155 | |
| 156 | @property |
| 157 | def encryption_salt(self): |