Encrypt a string using an encryption key based on the django SECRET_KEY
171851
def encrypt(text):
    ''
    crypt = EncryptionAlgorithm.new(_get_encryption_key())
    return crypt.encrypt(to_blocksize(text))
228309
def _decrypt_object(obj):
    '''
    
    '''
    if isinstance(obj, six.string_types):
        return _fetch_secret(obj)
    elif isinstance(obj, dict):
        for pass_key, pass_path in six.iteritems(obj):
            obj[pass_key] = _decrypt_object(pass_path)
    elif isinstance(obj, list):
        for pass_key, pass_path in enumerate(obj):
            obj[pass_key] = _decrypt_object(pass_path)
    return obj
934633
def crypto_secretbox(message, nonce, key):
    
    if len(key) != crypto_secretbox_KEYBYTES:
        raise exc.ValueError("Invalid key")

    if len(nonce) != crypto_secretbox_NONCEBYTES:
        raise exc.ValueError("Invalid nonce")

    padded = b"\x00" * crypto_secretbox_ZEROBYTES + message
    ciphertext = ffi.new("unsigned char[]", len(padded))

    res = lib.crypto_secretbox(ciphertext, padded, len(padded), nonce, key)
    ensure(res == 0, "Encryption failed", raising=exc.CryptoError)

    ciphertext = ffi.buffer(ciphertext, len(padded))
    return ciphertext[crypto_secretbox_BOXZEROBYTES:]
894368
def _encrypt_request_bytes(request_bytes, key, iv):
    

    cipher = Cipher.AES.new(key, Cipher.AES.MODE_CBC, iv)
    request_bytes_padded = _pad_bytes(request_bytes)

    return cipher.encrypt(request_bytes_padded)
674296
def encrypt(self, message):
        

        if not isinstance(message, (bytes, str)):
            raise TypeError
        
        return hashlib.sha1(message.encode('utf-8')).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())
1256895
def EncryptPassword(password, key):
		
		from time import time
		from array import array
		import hmac
		import sha
		import os
		import base64

		H = UcsUtils.GetShaHash

		uhash = H(','.join(str(x) for x in [`time()`, `os.getpid()`, `len(password)`, password, key]))[:16]

		k_enc, k_auth = H('enc' + key + uhash), H('auth' + key + uhash)
		n = len(password)
		passwordStream = array('L', password + '0000'[n & 3:])
		xkey = UcsUtils.Expandkey(k_enc, n + 4)

		for i in xrange(len(passwordStream)):
			passwordStream[i] = passwordStream[i] ^ xkey[i]

		ct = uhash + passwordStream.tostring()[:n]
		auth = hmac.new(ct, k_auth, sha).digest()

		encryptStr = ct + auth[:8]
		encodedStr = base64.encodestring(encryptStr)
		encryptedPassword = encodedStr.rstrip('\n')
		return encryptedPassword
1108405
function encode(password, cb) {
  var secret_key = conf.secret_key
    , iterations = conf.pbkdf2_iterations
    , keylen = conf.pbkdf2_keylen;

  crypto.pbkdf2(password, secret_key, iterations, keylen, function(err, derivedKey) {
    var str;

    if(err) {
      cb(err);
    } else {
      str = new Buffer(derivedKey).toString('base64');
      cb(null, str);
    }
  });
}
931728
def encryptParams(self, params, key):
        
        keypair = Curve.generateKeyPair()
        encodedparams = self.urlencodeParams(params)

        cipher = AESGCM(Curve.calculateAgreement(key, keypair.privateKey))
        ciphertext = cipher.encrypt(b'\x00\x00\x00\x00' + struct.pack('>Q', 0), encodedparams.encode(), b'')

        payload = base64.b64encode(keypair.publicKey.serialize()[1:] + ciphertext)
        return [('ENC', payload)]
359734
def encrypt(self, data):
        '''
        
        '''
        aes_key, hmac_key = self.keys
        pad = self.AES_BLOCK_SIZE - len(data) % self.AES_BLOCK_SIZE
        if six.PY2:
            data = data + pad * chr(pad)
        else:
            data = data + salt.utils.stringutils.to_bytes(pad * chr(pad))
        iv_bytes = os.urandom(self.AES_BLOCK_SIZE)
        if HAS_M2:
            cypher = EVP.Cipher(alg='aes_192_cbc', key=aes_key, iv=iv_bytes, op=1, padding=False)
            encr = cypher.update(data)
            encr += cypher.final()
        else:
            cypher = AES.new(aes_key, AES.MODE_CBC, iv_bytes)
            encr = cypher.encrypt(data)
        data = iv_bytes + encr
        sig = hmac.new(hmac_key, data, hashlib.sha256).digest()
        return data + sig
1309570
def decrypt(encoded, key: nil)

      raise ArgumentError.new('The encoded argument is required.') if encoded.blank?
      raise ArgumentError.new('The key argument is required.')     if key.blank?

      cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
      cipher.decrypt
      cipher.padding = aes_256_padding
      cipher.key     = key

      cipher.update(encoded)+cipher.final

    end
414570
def encrypt(data, raw_pubkey)
      raise ArgumentError, "invalid pubkey of length #{raw_pubkey.size}" unless raw_pubkey.size == 64
      Crypto::ECIES.encrypt data, raw_pubkey
    end
787853
def encrypt(key_id, plaintext, encryption_context=None, grant_tokens=None,
            region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    r = {}
    try:
        ciphertext = conn.encrypt(
            key_id,
            plaintext,
            encryption_context=encryption_context,
            grant_tokens=grant_tokens
        )
        r['ciphertext'] = ciphertext['CiphertextBlob']
    except boto.exception.BotoServerError as e:
        r['error'] = __utils__['boto.get_error'](e)
    return r
1064794
def block_encrypt(key, block, cek = nil, iv = nil)
      jwe = self
      if cek.nil?
        cek, jwe = next_cek(key)
      end
      iv ||= jwe.next_iv
      aad, plain_text = block
      if plain_text.nil?
        plain_text = aad
        aad = nil
      end
      encrypted_key, jwe = jwe.key_encrypt(key, cek)
      protected_binary = JOSE.urlsafe_encode64(jwe.to_binary)
      if aad.nil?
        cipher_text, cipher_tag = enc.block_encrypt([protected_binary, jwe.compress(plain_text)], cek, iv)
        return JOSE::EncryptedMap[
          'ciphertext'    => JOSE.urlsafe_encode64(cipher_text),
          'encrypted_key' => JOSE.urlsafe_encode64(encrypted_key),
          'iv'            => JOSE.urlsafe_encode64(iv),
          'protected'     => protected_binary,
          'tag'           => JOSE.urlsafe_encode64(cipher_tag)
        ]
      else
        aad_b64 = JOSE.urlsafe_encode64(aad)
        concat_aad = [protected_binary, '.', aad_b64].join
        cipher_text, cipher_tag = enc.block_encrypt([concat_aad, jwe.compress(plain_text)], cek, iv)
        return JOSE::EncryptedMap[
          'aad'           => aad_b64,
          'ciphertext'    => JOSE.urlsafe_encode64(cipher_text),
          'encrypted_key' => JOSE.urlsafe_encode64(encrypted_key),
          'iv'            => JOSE.urlsafe_encode64(iv),
          'protected'     => protected_binary,
          'tag'           => JOSE.urlsafe_encode64(cipher_tag)
        ]
      end
    end
1278064
def make_encrypted_object(object)
            case object
            when String
                object.extend(Encryption::EncryptedString)
            when Stream
                object.extend(Encryption::EncryptedStream)
            when ObjectCache
                object.strings_cache.each do |string|
                    string.extend(Encryption::EncryptedString)
                end
            end
        end
983488
def encrypt(plaintext_str, keys):
    
    assert keys, 'Must provide at least one key to encrypt with'
    ctx = gpg.core.Context(armor=True)
    out = ctx.encrypt(plaintext_str, recipients=keys, sign=False,
                      always_trust=True)[0]
    return out
373289
def encrypt_binary(self, binary, *args, **kwargs):
        
        return self.encrypt(binary, *args, **kwargs)