def decryptData(key, encryptedData): """Decrypts the apk data using the specified AES key""" aes = AES.new(key, AES.MODE_ECB) return ''.join( util.unpad(aes.decrypt(c)) for c in util.chunk(encryptedData, constants.blockSize + constants.paddingSize))
def decrypt(self, c: bytes): blocks = [] for i in progressbar.progressbar(range(0, len(c), self.rsa.oblock_size)): ciphertext_block = c[i:i + self.rsa.oblock_size] block = self._decrypt_block(ciphertext_block) blocks.append(block) return unpad(b"".join(blocks))
def decrypt_filename(self, cipher, key): """ Decrypts filename using AES in ECB mode """ AES_cipher = AES.new(key, AES.MODE_ECB) name = AES_cipher.decrypt( bytes.fromhex(util.remove_cipher_extension(cipher))) return util.unpad(name).decode()
def bitmap_to_mtn_pixels(self): # 1. Rotate it to the left, because the pixels need to be structured as height slices # 2. Bitmaps are bottom to top, and mountains are top to bottom, so reverse/mirror the array # 3. Remove the sky pixels from the maxtrix rows. positioned_matrix = mirror_array( rotate_matrix_90_degrees_left(self.bitmap_struct.pixels)) return unpad(positioned_matrix, self.sky_palette_value)
def parse_decrypt_do87(self,rapdu): """ decrypt a do87 object if contained in the (encrypted) response apdu :param rapdu: the encrypted response apdu :return: the decrypted data """ if(not rapdu[0] == 0x87): if(self.debug): self.__trace_response(None) return None else: head, enc_data = dec_ber_tlv_len(rapdu[1:]) data = unpad(self.des3dec(enc_data[1:])) if(self.debug): self.__trace_response(data) return data
def decrypt_file(self, path, key, res_path, force): """ Decrypts the file located in <path> and stores it as res_path/<encrypted file name> File names are encrypted using the same <name_iv> stored is the <CREDENTIALS> folder """ cipher = util.get_file_bytes(path) # encrypted file == 16B IV | xB encrypted file content iv = cipher[:backup_client.IV_SIZE] cipher = cipher[backup_client.IV_SIZE:] AES_cip = AES.new(key, AES.MODE_CBC, iv) plain = bytes(AES_cip.decrypt(cipher)) plain = util.unpad(plain) res_name = self.decrypt_filename( util.remove_cipher_extension(util.get_file_name(path)), key) util.write_file_bytes(plain, res_path, res_name, force) return res_name
def decryptData(key, encryptedData): """Decrypts the apk data using the specified AES key""" aes = AES.new(key, AES.MODE_ECB) return ''.join(util.unpad(aes.decrypt(c)) for c in util.chunk(encryptedData, constants.blockSize + constants.paddingSize))