This method encrypts the content.
    
    :rtype: bytes
320236
def encrypt_aes_cbc(cleartext, key, iv):
    
    if isinstance(cleartext, unicode):
        cleartext = cleartext.encode('utf8')
    elif isinstance(cleartext, bytearray):
        cleartext = bytes(cleartext)
    if not isinstance(cleartext, bytes):
        raise TypeError("content to encrypt must by bytes.")
    
    aes = AES.new(key, AES.MODE_CBC, iv)
    padding = AES.block_size - (len(cleartext) % AES.block_size)
    cleartext += chr(padding).encode('utf-8') * padding # the encode() is for py3k compat
    return aes.encrypt(cleartext)
431706
def content(self):
        

        if self._content is not None:
            return self._content

        if self._content_consumed:
            raise RuntimeError('The content for this response was '
                               'already consumed')

        # Read the contents.
        try:
            self._content = self.raw.read()
        except AttributeError:
            return None


        # Decode GZip'd content.
        if 'gzip' in self.headers.get('content-encoding', ''):
            try:
                self._content = decode_gzip(self._content)
            except zlib.error:
                pass

        # Decode unicode content.
        if self.config.get('decode_unicode'):
            self._content = get_unicode_from_response(self)

        self._content_consumed = True
        return self._content
358216
def encrypt(data)
      Digest::const_get(algorithm.upcase).hexdigest(build(data, salt))
    end
826228
def encrypt(options = {})
            raise EncryptionError, "PDF is already encrypted" if self.encrypted?

            #
            # Default encryption options.
            #
            params =
            {
                :user_passwd => '',
                :owner_passwd => '',
                :cipher => 'aes',            # :RC4 or :AES
                :key_size => 128,            # Key size in bits
                :hardened => false,          # Use newer password validation (since Reader X)
                :encrypt_metadata => true,   # Metadata shall be encrypted?
                :permissions => Encryption::Standard::Permissions::ALL    # Document permissions
            }.update(options)

            # Get the cryptographic parameters.
            version, revision = crypto_revision_from_options(params)

            # Create the security handler.
            handler, encryption_key = create_security_handler(version, revision, params)

            # Turn this document into an EncryptedDocument instance.
            self.extend(Encryption::EncryptedDocument)
            self.encryption_handler = handler
            self.encryption_key = encryption_key

            self
        end
854384
def encrypt(self, text, app_id):
        
        text = b"".join(
            [
                to_binary(self.get_random_string()),
                struct.pack(b"I", socket.htonl(len(to_binary(text)))),
                to_binary(text),
                to_binary(app_id)
            ]
        )
        text = pkcs7.encode(text)
        encryptor = self.cipher.encryptor()
        ciphertext = to_binary(encryptor.update(text) + encryptor.finalize())
        return base64.b64encode(ciphertext)
1321653
def encrypt(receiver_pubhex: str, msg: bytes) -> bytes:
    
    disposable_key = generate_key()
    receiver_pubkey = hex2pub(receiver_pubhex)
    aes_key = derive(disposable_key, receiver_pubkey)
    cipher_text = aes_encrypt(aes_key, msg)
    return disposable_key.public_key.format(False) + cipher_text
776910
def decrypt(encrypted)
      fail ArgumentError, 'No cipher text supplied.' if encrypted.nil? || encrypted.empty?

      matches = CIPHER_PATTERN.match(encrypted)

      fail ArgumentError, 'Cipher text has an unsupported format.' if matches.nil?

      cipher = self.class.cipher
      cipher.decrypt
      cipher.key = Base64.decode64(@key)
      cipher.iv = Base64.decode64(matches[1])
      decrypted = cipher.update(Base64.decode64(matches[2]))

      decrypted << cipher.final
    end
879444
def encrypt(s, pk, pk_format=SER_COMPACT, mac_bytes=10, curve=None):
    
    curve = (Curve.by_pk_len(len(pk)) if curve is None
             else Curve.by_name(curve))
    p = curve.pubkey_from_string(pk, pk_format)
    return p.encrypt(s, mac_bytes)
310850
def set_response_content_md5(self):
        
        self.response.content_md5 = hashlib.md5(self.response.body).hexdigest()
1351510
def encrypt(self, data, nounce=None):
        """"""
        if nounce is None:
            nounce = self._out_counter.to_bytes(length=8, byteorder='little')
            self._out_counter += 1

        return self._enc_out.seal(b'\x00\x00\x00\x00' + nounce, data, bytes())
373289
def encrypt_binary(self, binary, *args, **kwargs):
        
        return self.encrypt(binary, *args, **kwargs)
527911
def to_bytes(self, errors='strict'):
        ''''''
        return str(self).encode(self.encoding, errors=errors)
1312121
def encrypt_to_file(contents, filename):
    
    if not filename.endswith('.enc'):
        raise ValueError("%s does not end with .enc" % filename)

    key = Fernet.generate_key()
    fer = Fernet(key)

    encrypted_file = fer.encrypt(contents)

    with open(filename, 'wb') as f:
        f.write(encrypted_file)

    return key
225211
def encrypt(value)
      return value if is_empty_val(value)
      c = cipher.encrypt
      c.key = Digest::SHA256.digest(cipher_key)
      c.iv = iv = c.random_iv
      Base64.encode64(iv) + Base64.encode64(c.update(value.to_s) + c.final)
    end
629192
def encrypt(self, data, pad=True):
        
        encrypted_data = b""
        for i in range(0, len(data), 8):
            block = data[i:i + 8]
            block_length = len(block)
            if block_length != 8 and pad:
                block += b"\x00" * (8 - block_length)
            elif block_length != 8:
                raise ValueError("DES encryption must be a multiple of 8 "
                                 "bytes")
            encrypted_data += self._encode_block(block)

        return encrypted_data
876665
def secret_key_bytes(self):
        ''' 

        '''
        if not hasattr(self, '_secret_key_bytes'):
            key = self.secret_key()
            if key is None:
                self._secret_key_bytes = None
            else:
                self._secret_key_bytes = codecs.encode(key, "utf-8")
        return self._secret_key_bytes
1127560
def to_bytes(self):
        '''
        
        '''
        header = self._make_header(self._checksum)
        return header + self._options.to_bytes()