Returns plain text from *source_text*, a base64 AES encrypted string
    as generated with openssl.

        $ echo '_source_text_' | openssl aes-256-cbc -a -k _passphrase_ -p
        salt=...
        key=...
        iv=...
        _full_encrypted_
13582
def decrypt(source_text, passphrase, debug_stmt=None):
    
    if debug_stmt is None:
        debug_stmt = "decrypt"
    full_encrypted = b64decode(source_text)
    salt = full_encrypted[8:IV_BLOCK_SIZE]
    encrypted_text = full_encrypted[IV_BLOCK_SIZE:]
    key, iv_ = _openssl_key_iv(passphrase, salt)
    cipher = Cipher(
        algorithms.AES(key), modes.CBC(iv_), default_backend()
    ).decryptor()
    plain_text = cipher.update(encrypted_text)
    plain_text += cipher.finalize()
    # PKCS#7 padding
    if six.PY2:
        padding = ord(plain_text[-1])
    else:
        padding = plain_text[-1]
    plain_text = plain_text[:-padding]
    if hasattr(plain_text, 'decode'):
        plain_text = plain_text.decode('utf-8')
    _log_debug(salt, key, iv_, source_text, plain_text,
        passphrase=passphrase, debug_stmt=debug_stmt)
    return plain_text
885405
function _crypt($text, $mode)
    {
        if ($this->changed) {
            $this->_setup();
            $this->changed = false;
        }

        $stream = &$this->stream[$mode];
        if ($this->continuousBuffer) {
            $i = &$stream[0];
            $j = &$stream[1];
            $keyStream = &$stream[2];
        } else {
            $i = $stream[0];
            $j = $stream[1];
            $keyStream = $stream[2];
        }

        $len = strlen($text);
        for ($k = 0; $k < $len; ++$k) {
            $i = ($i + 1) & 255;
            $ksi = $keyStream[$i];
            $j = ($j + $ksi) & 255;
            $ksj = $keyStream[$j];

            $keyStream[$i] = $ksj;
            $keyStream[$j] = $ksi;
            $text[$k] = $text[$k] ^ chr($keyStream[($ksj + $ksi) & 255]);
        }

        return $text;
    }
1283746
private static function cryptOpenSSl(
        $key,
        $crypt_text,
        $method = self::DEFAULT_CHIPPER
    ) {
        /**
         * ------------------------------------
         * Doing decryption
         * ------------------------------------
         */
        $chipper = openssl_get_cipher_methods();
        if (!is_string($method) || !in_array($method, $chipper)) {
            $method = self::DEFAULT_CHIPPER;
        }
        $iv_len = openssl_cipher_iv_length($method);
        $strong = false;
        $iv = openssl_random_pseudo_bytes($iv_len, $strong);
        return [
            @openssl_encrypt($crypt_text, $method, $key, 0, $iv),
            $method,
            $iv
        ];
    }
199486
static public function encryptString($plaintext_string, $key_name) {
        $kms = self::getService();
        $base64_encoded_json = base64_encode($plaintext_string);
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($base64_encoded_json);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );
        return $response['ciphertext'];
    }
1344352
public synchronized String encrypt(String plaintext) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
            md.update(plaintext.getBytes(UTF8));
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "Should not happen!", e);
        }
        byte raw[] = md.digest();

        return encode(raw);
    }
216092
function encrypt($plaintext)
    {
        if ($this->engine == self::ENGINE_OPENSSL) {
            $temp = $this->key;
            $this->key = $this->orig_key;
            $result = parent::encrypt($plaintext);
            $this->key = $temp;
            return $result;
        }

        return parent::encrypt($plaintext);
    }
38637
function decrypt($enc_string,$base64_decode=true){
		if(is_null($enc_string) || empty($enc_string)) return NULL;
		if(!$this->verified) $this->verify();
		//decrypt and return
		if($base64_decode) $enc_string = base64_decode($enc_string);
		$plain_string = mcrypt_decrypt(
			 self::$crypt_cipher
			,base64_decode($this->key)
			,$enc_string
			,self::$crypt_mode
			,base64_decode($this->iv)
		);
		//get size of string from atom
		$size = unpack('N',substr($plain_string,0,4));
		$size = array_shift($size);
		//make sure we have the original string
		$plain_string = substr($plain_string,4,$size);
		return $plain_string;
	}
542871
public String encrypt(String text, PublicKey key) throws MangooEncryptionException {
        Objects.requireNonNull(text, Required.PLAIN_TEXT.toString());
        Objects.requireNonNull(text, Required.PUBLIC_KEY.toString());
        
        String encrypt = null;
        try {
            byte[] cipherText = encrypt(text.getBytes(StandardCharsets.UTF_8), key);
            encrypt = encodeBase64(cipherText);
        } catch (MangooEncryptionException e) {
            throw new MangooEncryptionException("Failed to encrypt clear text with public key", e);
        }
        
        return encrypt;
    }
363375
public function encrypt($plainText = '')
    {
        $cipher = new \phpseclib\Crypt\AES();
        // could use AES::MODE_CBC
        // keys are null-padded to the closest valid size
        // longer than the longest key and it's truncated
        $cipher->setKeyLength($this->keyLength);
        $cipher->setKey($this->key);
//        $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8);
        // the IV defaults to all-NULLs if not explicitly defined
        //$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6');

        return base64_encode($cipher->encrypt($plainText));
    }
558048
def decode_aes256_cbc_base64(data, encryption_key):
    """"""
    if not data:
        return b''
    else:
        # LastPass AES-256/CBC/base64 encryted string starts with an "!".
        # Next 24 bytes are the base64 encoded IV for the cipher.
        # Then comes the "|".
        # And the rest is the base64 encoded encrypted payload.
        return decode_aes256(
            'cbc',
            decode_base64(data[1:25]),
            decode_base64(data[26:]),
            encryption_key)
462986
def _decrypt_ciphertext(cipher):
    '''
    
    '''
    try:
        cipher = salt.utils.stringutils.to_unicode(cipher).replace(r'\n', '\n')
    except UnicodeDecodeError:
        # ciphertext is binary
        pass
    cipher = salt.utils.stringutils.to_bytes(cipher)
    cmd = [_get_gpg_exec(), '--homedir', _get_key_dir(), '--status-fd', '2',
           '--no-tty', '-d']
    proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False)
    decrypted_data, decrypt_error = proc.communicate(input=cipher)
    if not decrypted_data:
        try:
            cipher = salt.utils.stringutils.to_unicode(cipher)
        except UnicodeDecodeError:
            # decrypted data contains undecodable binary data
            pass
        log.warning(
            'Could not decrypt cipher %s, received: %s',
            cipher,
            decrypt_error
        )
        return cipher
    else:
        try:
            decrypted_data = salt.utils.stringutils.to_unicode(decrypted_data)
        except UnicodeDecodeError:
            # decrypted data contains undecodable binary data
            pass
        return decrypted_data
12053
public static function encrypt($text)
    {
        if (function_exists('mcrypt_encrypt')) {
            $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
            $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
            $len = mcrypt_get_key_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);

            /** @var \Concrete\Core\Config\Repository\Repository $config */
            $config = \Core::make('config/database');
            $text = base64_encode(mcrypt_encrypt(MCRYPT_XTEA, substr($config->get('concrete.security.token.encryption'), 0, $len), $text, MCRYPT_MODE_ECB, $iv));
        }

        return $text;
    }
839892
public static String encrypt(String secretKey, String plainText) {
        if (plainText == null) {
            return null;
        } else if (plainText.startsWith("$CRYPT::")) {
             // Avoid encrypting already encrypted text - APIMAN-1201
             return plainText;
        }
        
        byte[] encrypted;
        Cipher cipher;
        try {
            SecretKeySpec skeySpec = keySpecFromSecretKey(secretKey);
            
            cipher = Cipher.getInstance("AES"); //$NON-NLS-1$
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) {
            throw new RuntimeException(e);
        }
        try {
            encrypted = cipher.doFinal(plainText.getBytes());
        } catch (IllegalBlockSizeException | BadPaddingException e) {
            throw new RuntimeException(e);
        }
        return "$CRYPT::" + new String(Base64.encodeBase64(encrypted)); //$NON-NLS-1$
    }
228069
public String decrypt(final String pEncryptedText) throws GeneralSecurityException {
        byte[] allEncryptedBytes = Base64Util.decode(pEncryptedText);
        int totalLen = allEncryptedBytes.length;
        byte[] salt = new byte[SALT_SIZE];

        System.arraycopy(allEncryptedBytes, 0, salt, 0, SALT_SIZE);
        byte padLen = allEncryptedBytes[SALT_SIZE];

        byte[] encryptedBytes = new byte[totalLen - SALT_SIZE - 1 - padLen];
        System.arraycopy(allEncryptedBytes, SALT_SIZE + 1, encryptedBytes, 0, encryptedBytes.length);

        Cipher cipher = createCipher(salt, Cipher.DECRYPT_MODE);
        byte[] clearBytes = cipher.doFinal(encryptedBytes);

        return new String(clearBytes, Charset.forName("UTF-8"));
    }
1224943
public static String encrypt(String key, String plainText) {
        SecretKey secret = new SecretKeySpec(Base64.decodeBase64(key.getBytes(StandardCharsets.UTF_8)), "AES");
        return encryptBouncyCastle(secret, plainText);
    }
31753
def rsa_base64_sign_str(self, plain, b64=True):
        
        with open(self.key_file) as fp:
            key_ = RSA.importKey(fp.read())
            # h = SHA.new(plain if sys.version_info < (3, 0) else plain.encode('utf-8'))
            plain = helper.to_bytes(plain)
            # if hasattr(plain, 'encode'):
            #     plain = plain.encode()
            h = SHA.new(plain)
            cipher = pkcs.new(key_).sign(h)
            cip = base64.b64encode(cipher) if b64 else cipher
            return helper.to_str(cip)
269582
def decrypt_text(self, text, *args, **kwargs):
        
        b = text.encode("utf-8")
        token = base64.b64decode(b)
        return self.decrypt(token, *args, **kwargs).decode("utf-8")