'Test that the given GPG message can be decrypted with the given key
(identified by its fingerprint).'

def _can_decrypt_with_key(self, msg, key_fpr, passphrase=None):

    gpg_tmp_dir = tempfile.mkdtemp()
    gpg = gnupg.GPG(homedir=gpg_tmp_dir)
    pubkey = self.gpg.export_keys(key_fpr)
    seckey = self.gpg.export_keys(key_fpr, secret=True)
    for key in (pubkey, seckey):
        gpg.import_keys(key)
    if passphrase:
        passphrase = crypto_util.hash_codename(passphrase, salt=crypto_util.SCRYPT_GPG_PEPPER)
    decrypted_data = gpg.decrypt(msg, passphrase=passphrase)
    self.assertTrue(decrypted_data.ok, 'Could    not    decrypt    msg    with    key,    gpg    says:    {}'.format(decrypted_data.stderr))
    shutil.rmtree(gpg_tmp_dir)
