Encrypts a string using a secret

@param   string      $original_string        Original string
@param   string      $cipher_key             Secret used to encrypt

@return string
185357
public function encrypt($original_string, $cipher_key)
    {
        $cipher_key = $this->_genKey($cipher_key);

        $ivSize = openssl_cipher_iv_length('AES-256-CBC');
        $iv = openssl_random_pseudo_bytes($ivSize);

        $cipher_text = $iv . openssl_encrypt($original_string, 'AES-256-CBC', $cipher_key, OPENSSL_RAW_DATA, $iv);

        return $this->_genHmac($cipher_text, $cipher_key) . $cipher_text;
    }
1036893
function decrypt($ciphertext)
    {
        if ($this->k <= 0) {
            return false;
        }

        $ciphertext = str_split($ciphertext, $this->k);
        $ciphertext[count($ciphertext) - 1] = str_pad($ciphertext[count($ciphertext) - 1], $this->k, chr(0), STR_PAD_LEFT);

        $plaintext = '';

        switch ($this->encryptionMode) {
            case self::ENCRYPTION_NONE:
                $decrypt = '_raw_encrypt';
                break;
            case self::ENCRYPTION_PKCS1:
                $decrypt = '_rsaes_pkcs1_v1_5_decrypt';
                break;
            //case self::ENCRYPTION_OAEP:
            default:
                $decrypt = '_rsaes_oaep_decrypt';
        }

        foreach ($ciphertext as $c) {
            $temp = $this->$decrypt($c);
            if ($temp === false) {
                return false;
            }
            $plaintext.= $temp;
        }

        return $plaintext;
    }
100100
private Function<Object, String> createDecryptor() throws GeneralSecurityException {
		Cipher cipher = Cipher.getInstance(transformationType);
		if (useIV) {
			cipher.init(Cipher.DECRYPT_MODE, secretKey,
					encryptCipher.getParameters().getParameterSpec(IvParameterSpec.class));
		} else {
			cipher.init(Cipher.DECRYPT_MODE, secretKey);
		}

		return secret -> {
			if (secret == null) {
				return null;
			}

			String secretStr = secret.toString();
			if (!secretStr.isEmpty()) {
				synchronized (cipher) {
					try {
						return decrypt(cipher, secretKey, secretStr);
					} catch (Exception ex) {
						return secretStr;
					}
				}
			} else {
				return secretStr;
			}
		};
	}
450949
function cipher(string) {

        if(string) {

            if ( typeof pw !== 'string' || pw.length < 8 ) {
                throw new Error('Please set a password with 8 or ' +
                    'more chars on process.env.CIPHER_UTIL_PW!');
            }

            if ( typeof algo !== 'string' || algo.length < 1 ) {
                throw new Error('Please choose an algorithm' +
                    ' on process.env.CIPHER_UTIL_ALGO!');
            }

            var iv = crypto.randomBytes(ivBlock),

            ciphered = crypto.createCipheriv(algo, pw, iv),

            encrypted = [ciphered.update(string)];

            encrypted.push(ciphered.final());

            return Buffer.concat([iv, Buffer.concat(encrypted)]).toString(enc);

        }

        return null;

    }
908294
public static function encrypt($str, $key,$expire=0) {
        $expire = sprintf('%010d', $expire ? $expire + time():0);
        $str    =   $expire.$str;
        $v = self::str2long($str, true);
        $k = self::str2long($key, false);
        $n = count($v) - 1;

        $z = $v[$n];
        $y = $v[0];
        $delta = 0x9E3779B9;
        $q = floor(6 + 52 / ($n + 1));
        $sum = 0;
        while (0 < $q--) {
            $sum = self::int32($sum + $delta);
            $e = $sum >> 2 & 3;
            for ($p = 0; $p < $n; $p++) {
                $y = $v[$p + 1];
                $mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
                $z = $v[$p] = self::int32($v[$p] + $mx);
            }
            $y = $v[0];
            $mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
            $z = $v[$n] = self::int32($v[$n] + $mx);
        }
        return self::long2str($v, false);
    }
436993
function decrypt($ciphertext)
    {
        if ($this->engine == self::ENGINE_OPENSSL) {
            $temp = $this->key;
            $this->key = $this->orig_key;
            $result = parent::decrypt($ciphertext);
            $this->key = $temp;
            return $result;
        }

        return parent::decrypt($ciphertext);
    }
120988
private String decryptInternal(SecretKeySpec key, byte[] encryptedBytes) {
        try {
            Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
            return new String(decryptedBytes, ENCODING);
        } catch (GeneralSecurityException e) {
            throw new RuntimeException("Exception during decryptInternal: " + e, e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Exception during encryptInternal: " + e, e);
        }
    }
1324459
public static SecretKey generateKey(String cipherAlgorithm) throws NoSuchAlgorithmException {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(cipherAlgorithm);
        keyGenerator.init(secureRandom);

        return keyGenerator.generateKey();
    }
1098183
function decrypt($ciphertext)
    {
        if ($this->k <= 0) {
            return false;
        }

        $ciphertext = str_split($ciphertext, $this->k);
        $ciphertext[count($ciphertext) - 1] = str_pad($ciphertext[count($ciphertext) - 1], $this->k, chr(0), STR_PAD_LEFT);

        $plaintext = '';

        switch ($this->encryptionMode) {
            case CRYPT_RSA_ENCRYPTION_NONE:
                $decrypt = '_raw_encrypt';
                break;
            case CRYPT_RSA_ENCRYPTION_PKCS1:
                $decrypt = '_rsaes_pkcs1_v1_5_decrypt';
                break;
            //case CRYPT_RSA_ENCRYPTION_OAEP:
            default:
                $decrypt = '_rsaes_oaep_decrypt';
        }

        foreach ($ciphertext as $c) {
            $temp = $this->$decrypt($c);
            if ($temp === false) {
                return false;
            }
            $plaintext.= $temp;
        }

        return $plaintext;
    }
1275596
public function read($key, $ciphertext)
    {
        $ciphertext = strval($ciphertext);
        return (strlen($key) && strlen($ciphertext))
            ? $this->_getCipherOb($key)->decrypt($ciphertext)
            : '';
    }
1013760
public function encrypt($plain_string,$base64_encode=true){
		if(!$this->verified) $this->verify();
		//add size atom to encrypted string
		$size = pack('N',strlen($plain_string));
		$plain_string = $size.$plain_string;
		//encrypt and return
		$enc_string = mcrypt_encrypt(
			 self::$crypt_cipher
			,base64_decode($this->key)
			,$plain_string
			,self::$crypt_mode
			,base64_decode($this->iv)
		);
		if($base64_encode) return base64_encode($enc_string);
		return $enc_string;
	}
39286
function encrypt (str) {
    var cipher = crypto.createCipher(algorithm, key)
      , crypted = cipher.update(str, from, to) + cipher.final(to)
    return crypted;
  }
1212093
public static String decryptString(String string, String key) {
        if (!StringUtils.isEmpty(string)) {
            try {
                return Encryption.decryptString(
                        string, key);
            } catch (EncryptionException e) {
                LOG.error(e.getMessage());
            }
        }
        return "";
    }
92352
public final String decryptString(SecretKey sharedKey, byte[] encryptedString) {
        logger.entry();
        try (ByteArrayInputStream input = new ByteArrayInputStream(encryptedString);
                ByteArrayOutputStream output = new ByteArrayOutputStream()) {
            decryptStream(sharedKey, input, output);
            output.flush();
            String string = output.toString("UTF-8");
            logger.exit();
            return string;
        } catch (IOException e) {
            // should never happen!
            RuntimeException exception = new RuntimeException("An unexpected exception occured while trying to decrypt a string.", e);
            logger.error(exception.toString());
            throw exception;
        }
    }
1159525
public function encrypt(string $plainText, ContentEncryptionKey $contentEncryptionKey, Nonce $nonce, Salt $salt, PublicKey $senderPublicKey) : Cipher
    {
        return $this->crypt->encrypt($plainText, $contentEncryptionKey, $nonce, $salt, $senderPublicKey);
    }
1090795
public function encrypt($string, $key = null, $iv = null)
    {
        $key = $key ?: $this->getKey();
        $iv = $iv ?: $this->getIv();

        return $this->cipher->encrypt($string, $key, $iv);
    }
99115
public static function generate_secret(
		$data, $key=null, $length=64
	) {
		if (!$key)
			$key = uniqid() . (string)mt_rand();
		$bstr = $data . $key;
		$bstr = hash_hmac('sha256', $bstr, $key, true);
		$bstr = base64_encode($bstr);
		$bstr = str_replace(['/', '+', '='], '', $bstr);
		return substr($bstr, 0, $length);
	}