Decrypts the encrypted ice file
170484
def thaw_decrypt(vault_client, src_file, tmp_dir, opt):
    """"""

    if not os.path.isdir(opt.secrets):
        LOG.info("Creating secret directory %s", opt.secrets)
        os.mkdir(opt.secrets)

    zip_file = "%s/aomi.zip" % tmp_dir

    if opt.gpg_pass_path:
        gpg_path_bits = opt.gpg_pass_path.split('/')
        gpg_path = '/'.join(gpg_path_bits[0:len(gpg_path_bits) - 1])
        gpg_field = gpg_path_bits[len(gpg_path_bits) - 1]
        resp = vault_client.read(gpg_path)
        gpg_pass = None
        if resp and 'data' in resp and gpg_field in resp['data']:
            gpg_pass = resp['data'][gpg_field]
            if not gpg_pass:
                raise aomi.exceptions.GPG("Unable to retrieve GPG password")

            LOG.debug("Retrieved GPG password from Vault")
            if not decrypt(src_file, zip_file, passphrase=gpg_pass):
                raise aomi.exceptions.GPG("Unable to gpg")

        else:
            raise aomi.exceptions.VaultData("Unable to retrieve GPG password")
    else:
        if not decrypt(src_file, zip_file):
            raise aomi.exceptions.GPG("Unable to gpg")

    return zip_file
847476
def _decrypt(self, data, key):
        """"""
        seed1 = key
        seed2 = 0xEEEEEEEE
        result = BytesIO()

        for i in range(len(data) // 4):
            seed2 += self.encryption_table[0x400 + (seed1 & 0xFF)]
            seed2 &= 0xFFFFFFFF
            value = struct.unpack("<I", data[i*4:i*4+4])[0]
            value = (value ^ (seed1 + seed2)) & 0xFFFFFFFF

            seed1 = ((~seed1 << 0x15) + 0x11111111) | (seed1 >> 0x0B)
            seed1 &= 0xFFFFFFFF
            seed2 = value + seed2 + (seed2 << 5) + 3 & 0xFFFFFFFF

            result.write(struct.pack("<I", value))

        return result.getvalue()
923408
def decrypt(self, enctext, key_file=None, id_attr=''):
        
        if not id_attr:
            id_attr = self.id_attr

        if not isinstance(key_file, list):
            key_file = [key_file]

        key_files = [
            key for key in itertools.chain(key_file, self.enc_key_files) if key
        ]
        for key_file in key_files:
            try:
                dectext = self.crypto.decrypt(enctext, key_file, id_attr)
            except XmlsecError as e:
                continue
            else:
                if dectext:
                    return dectext

        errmsg = "No key was able to decrypt the ciphertext. Keys tried: {keys}"
        errmsg = errmsg.format(keys=key_files)
        raise DecryptError(errmsg)
234793
def decrypt_file(in_path_or_file, out_path_or_file, passphrase,
                 curve='secp160r1', mac_bytes=10, chunk_size=4096):
    
    close_in, close_out = False, False
    in_file, out_file = in_path_or_file, out_path_or_file
    try:
        if stringlike(in_path_or_file):
            in_file = open(in_path_or_file, 'rb')
            close_in = True
        if stringlike(out_path_or_file):
            out_file = open(out_path_or_file, 'wb')
            close_out = True
        _decrypt_file(in_file, out_file, passphrase, curve, mac_bytes,
                      chunk_size)
    finally:
        if close_out:
            out_file.close()
        if close_in:
            in_file.close()
311854
def Decrypt(self, encrypted_data):
    
    index_split = -(len(encrypted_data) % AES.block_size)
    if index_split:
      remaining_encrypted_data = encrypted_data[index_split:]
      encrypted_data = encrypted_data[:index_split]
    else:
      remaining_encrypted_data = b''

    decrypted_data = self._aes_cipher.decrypt(encrypted_data)

    return decrypted_data, remaining_encrypted_data
699839
def decrypt(self, data, nounce=None):
        """"""
        if nounce is None:
            nounce = self._in_counter.to_bytes(length=8, byteorder='little')
            self._in_counter += 1

        decrypted = self._enc_in.open(
            b'\x00\x00\x00\x00' + nounce, data, bytes())

        if not decrypted:
            raise Exception('data decrypt failed')  # TODO: new exception

        return bytes(decrypted)
366829
def do_heavy_work(self, block):
        
        cipher_key = self.gen_key(32)
        in_file_path = block.latest_file_info.path
        dst_file_path = block.processed_data_file_info.path + self.get_extension()
        self.log.debug("Encrypting file '%s' with key '%s' to file '%s'",
                       in_file_path, cipher_key, dst_file_path)
        self.encrypt_file(key=cipher_key,
                          in_filename=in_file_path,
                          out_filename=dst_file_path)
        block.cipher_key = cipher_key
        block.ciphered_file_info = FileInfo(dst_file_path)
        block.latest_file_info = block.ciphered_file_info
        return block
32425
def decrypt(self, encrypted):
        
        fernet = Fernet(self.decryption_cipher_key)
        return fernet.decrypt(encrypted)
586768
function decryptChunk(data) {
  try {
    var decodedData = atob(data);
    var decryptedChunk = this.__key.decrypt(decodedData, 'RSAES-PKCS1-V1_5');
    return decryptedChunk;
  } catch(e) {
    return e;
  }
}
1181913
def rsa_base64_decrypt(self, cipher, b64=True):
        
        with open(self.key_file) as fp:
            key_ = RSA.importKey(fp.read())
            _cip = PKCS1_v1_5.new(key_)
            cipher = base64.b64decode(cipher) if b64 else cipher
            plain = _cip.decrypt(cipher, Random.new().read(15 + SHA.digest_size))
            return helper.to_str(plain)
267621
def decrypt(data, digest=True):
    """"""
    alg, _, data = data.rpartition("$")
    if not alg:
        return data
    data = _from_hex_digest(data) if digest else data
    try:
        return implementations["decryption"][alg](
            data, implementations["get_key"]()
        )
    except KeyError:
        raise CryptError("Can not decrypt key for algorithm: %s" % alg)
1267054
def decrypt(self, ciphertext):
        ''

        if len(ciphertext) != 16:
            raise ValueError('wrong block length')

        rounds = len(self._Kd) - 1
        (s1, s2, s3) = [3, 2, 1]
        a = [0, 0, 0, 0]

        # Convert ciphertext to (ints ^ key)
        t = [(_compact_word(ciphertext[4 * i:4 * i + 4]) ^ self._Kd[0][i]) for i in xrange(0, 4)]

        # Apply round transforms
        for r in xrange(1, rounds):
            for i in xrange(0, 4):
                a[i] = (self.T5[(t[ i          ] >> 24) & 0xFF] ^
                        self.T6[(t[(i + s1) % 4] >> 16) & 0xFF] ^
                        self.T7[(t[(i + s2) % 4] >>  8) & 0xFF] ^
                        self.T8[ t[(i + s3) % 4]        & 0xFF] ^
                        self._Kd[r][i])
            t = copy.copy(a)

        # The last round is special
        result = [ ]
        for i in xrange(0, 4):
            tt = self._Kd[rounds][i]
            result.append((self.Si[(t[ i           ] >> 24) & 0xFF] ^ (tt >> 24)) & 0xFF)
            result.append((self.Si[(t[(i + s1) % 4] >> 16) & 0xFF] ^ (tt >> 16)) & 0xFF)
            result.append((self.Si[(t[(i + s2) % 4] >>  8) & 0xFF] ^ (tt >>  8)) & 0xFF)
            result.append((self.Si[ t[(i + s3) % 4]        & 0xFF] ^  tt       ) & 0xFF)

        return result
27967
def encrypt_file(in_path_or_file, out_path_or_file, pk, pk_format=SER_COMPACT,
                 mac_bytes=10, chunk_size=4096, curve=None):
    
    close_in, close_out = False, False
    in_file, out_file = in_path_or_file, out_path_or_file
    try:
        if stringlike(in_path_or_file):
            in_file = open(in_path_or_file, 'rb')
            close_in = True
        if stringlike(out_path_or_file):
            out_file = open(out_path_or_file, 'wb')
            close_out = True
        _encrypt_file(in_file, out_file, pk, pk_format, mac_bytes, chunk_size,
                      curve)
    finally:
        if close_out:
            out_file.close()
        if close_in:
            in_file.close()
213759
def decrypt_filedata(data, keys):
    ''''''
    # The last 16 bytes / 128 bits of data is the GCM tag
    # https://www.w3.org/TR/WebCryptoAPI/#aes-gcm-operations :-
    # 7. Let ciphertext be equal to C | T, where '|' denotes concatenation.
    data.seek(-16, 2)
    tag = data.read()

    # now truncate the file to only contain encrypted data
    data.seek(-16, 2)
    data.truncate()
    data.seek(0)

    plain = tempfile.NamedTemporaryFile(mode='w+b', delete=False)

    pbar = progbar(fileSize(data))

    obj = Cryptodome.Cipher.AES.new(keys.encryptKey, Cryptodome.Cipher.AES.MODE_GCM, keys.encryptIV)
    prev_chunk = b''
    for chunk in iter(lambda: data.read(CHUNK_SIZE), b''):
        plain.write(obj.decrypt(prev_chunk))
        pbar.update(len(chunk))
        prev_chunk = chunk

    plain.write(obj.decrypt_and_verify(prev_chunk, tag))
    data.close()
    pbar.close()

    plain.seek(0)
    return plain
839485
function encrypt(key, iv, data) {
    if(!Buffer.isBuffer(key)) {
        assert(typeof key === 'string');
        key = Buffer.from(key, 'binary')
    }

    if(!Buffer.isBuffer(iv)) {
        assert(typeof iv === 'string');
        iv = Buffer.from(iv, 'binary')
    }

    if(!Buffer.isBuffer(data)) {
        assert(typeof data === 'string');
        data = Buffer.from(data, 'binary')
    }

    var crypted = aes.encipher(data, key, iv);

    crypted = Buffer.from(crypted, 'binary');
    
    let ret = Buffer.alloc(crypted.length*2);
    for(let i = 0; i < crypted.length; i++){
        ret[2*i] = (crypted[i] >> 4) + 97;
        ret[2*i+1] = (crypted[i] & 0x0F) + 97;
    }
    return ret.toString('binary');
}
1185580
def encrypt(data, digest=True):
    """"""
    alg = get_best_algorithm()
    enc = implementations["encryption"][alg](
        data, implementations["get_key"]()
    )
    return "%s$%s" % (alg, (_to_hex_digest(enc) if digest else enc))
610100
def decrypt(self, encryption_key, iv, encrypted_data):
        

        logger.info('Decrypting subtitles with length (%d bytes), key=%r',
            len(encrypted_data), encryption_key)
        return zlib.decompress(aes_decrypt(encryption_key, iv, encrypted_data))