doEncrypt

@param   string $data The data string to encrypt.
@param   string $key  The private key.
@param   string $iv   The public key.

@return  string
357307
protected function doEncrypt($data, $key, $iv)
    {
        $encrypted = sodium_crypto_secretbox($data, $iv, $key);

        $this->memzero($data);
        $this->memzero($key);
        $this->memzero($iv);

        return $encrypted;
    }
1352776
function encryptSimple($data) {
		$result = '';
		for($i=0; $i<strlen($data); $i++) {
			$char = substr($data, $i, 1);
			$keychar = substr($this->encPassword, ($i % strlen($this->encPassword))-1, 1);
			$char = chr(ord($char)+ord($keychar));
			$result.=$char;
		}
		return str_replace(array('+', '/'), array('-', '_'),base64_encode($result));
	}
112017
public static function decrypt($data)
    {
        $iv_size = openssl_cipher_iv_length(static::$cipher);
        
        $iv = Str::slice(sha1(static::$key), 0, $iv_size);

        return openssl_decrypt($data, static::$cipher, static::$key, 0, $iv);
    }
609089
def Decrypt(self, data, iv):
    """"""
    key = rdf_crypto.EncryptionKey(self.cipher.key)
    iv = rdf_crypto.EncryptionKey(iv)
    return rdf_crypto.AES128CBCCipher(key, iv).Decrypt(data)
786410
public function decrypt(string $data) {
        $keyHash = md5(Config::getConfig()->encrypt->key);
        $key = substr($keyHash, 0, mcrypt_get_key_size(self::$cipher, self::$mode));
        $iv = substr($keyHash, 0, mcrypt_get_block_size(self::$cipher, self::$mode));
        return mcrypt_decrypt(self::$cipher, $key, base64_decode($data), self::$mode, $iv);
    }
1059877
public function decryptData($encryptedData, $iv, &$data)
    {
        if (strlen($this->sessionKey) != 24) {
            return ErrorCode::$IllegalAesKey;
        }
        $aesKey = base64_decode($this->sessionKey);

        if (strlen($iv) != 24) {
            return ErrorCode::$IllegalIv;
        }
        $aesIV = base64_decode($iv);

        $aesCipher = base64_decode($encryptedData);

        $pc = new Prpcrypt($aesKey);
        $result = $pc->decrypt($aesCipher, $aesIV);

        if ($result[0] != 0) {
            return $result[0];
        }

        $dataObj = json_decode($result[1]);
        if ($dataObj == NULL) {
            return ErrorCode::$IllegalBuffer;
        }
        if ($dataObj->watermark->appid != $this->appid) {
            return ErrorCode::$IllegalBuffer;
        }
        $data = $result[1];
        return ErrorCode::$OK;
    }
200001
public function decrypt($data, $key = null, $iv = null)
    {
        $data = base64_decode($data);

        if (!$iv) {
            $iv = substr($data, 0, static::DEFAULT_RANDOM_BYTE_LENGTH);

            $data = substr($data, static::DEFAULT_RANDOM_BYTE_LENGTH);
        } else {
            if (substr($data, 0, strlen($iv)) === $iv) {
                $data = substr($data, strlen($iv));
            }
        }

        $key = sha1($iv . $key);

        return $this->doDecrypt($data, $key);
    }
1000273
public static function decrypt($data, $key, $iv) {
        $output = false;
        $encrypt_method = "AES-256-CBC";
        // hash
        $key = hash_hmac('sha256', $data, $iv);

        // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
        $iv = substr($iv, 0, 16);
        $output = openssl_decrypt(base64_decode($data), $encrypt_method, $key, 0, $iv);

        return $output;
    }
896694
def Encrypt(self, data, iv=None):
    """"""
    if iv is None:
      iv = rdf_crypto.EncryptionKey.GenerateKey(length=128)
    cipher = rdf_crypto.AES128CBCCipher(self.cipher.key, iv)
    return iv, cipher.Encrypt(data)
583179
protected function mcryptDecrypt($value, $iv)
	{
		return mcrypt_decrypt($this->cipher, $this->key, $value, $this->mode, $iv);
	}
375955
public function decrypt($data, $iv) {
        if (strlen($this->sessionKey) != 24) {
            throw new Exception('sessionkey 错误');
        }
        $aesKey = base64_decode($this->sessionKey);
        if (strlen($iv) != 24) {
            throw new Exception('iv 错误');
        }
        $aesIV = base64_decode($iv);
        $aesCipher = base64_decode($data);
        $result = openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
        $args = json_decode($result, true);
        if (empty($args)) {
            throw new Exception('aes 解密失败');
        }
        if ($args['watermark']['appid'] != $this->appid) {
            throw new Exception('解密后得到的buffer非法');
        }
        return $args;
    }
96533
public function encrypt($data, $iv, $key)
    {
        $this->crypt->setKey($key);
        $this->crypt->setSalt($iv);
        $encrypted = $this->crypt->encrypt($data);
        return substr($encrypted, strlen($iv));
    }
1324049
protected function doEncrypt($data, $key)
    {
        $encrypted = '';

        // Split up the input into a character array and get the number of characters.
        $chars = preg_split('//', $data, -1, PREG_SPLIT_NO_EMPTY);

        // Make sure private key is as long as chars length
        $key = str_repeat($key, (int) ceil(count($chars) / strlen($key)));

        // Get the XOR values between the ASCII values of the input and key characters for all input offsets.
        foreach ($chars as $i => $char) {
            $encrypted .= $this->intToHex(ord($key[$i]) ^ ord($char));
        }

        return $encrypted;
    }
983290
public function decrypt($data, Key $key)
	{
		// Validate key.
		if ($key->type != 'simple')
		{
			throw new \InvalidArgumentException('Invalid key of type: ' . $key->type . '.  Expected simple.');
		}

		$decrypted = '';
		$tmp = $key->public;

		// Convert the HEX input into an array of integers and get the number of characters.
		$chars = $this->_hexToIntArray($data);
		$charCount = count($chars);

		// Repeat the key as many times as necessary to ensure that the key is at least as long as the input.
		for ($i = 0; $i < $charCount; $i = strlen($tmp))
		{
			$tmp = $tmp . $tmp;
		}

		// Get the XOR values between the ASCII values of the input and key characters for all input offsets.
		for ($i = 0; $i < $charCount; $i++)
		{
			$decrypted .= chr($chars[$i] ^ ord($tmp[$i]));
		}

		return $decrypted;
	}
133394
public static function encrypt($data, $key) {

        static :: check();
        
        $iv = static :: random_bytes(16);
        
        //Encryption
        $ciphertext = openssl_encrypt($data, self :: METHOD, mb_substr($key, 0, 32, self :: ENCODING), OPENSSL_RAW_DATA, $iv);

        //Authentication
        $hmac = hash_hmac(self :: ALGORITHM, $iv . $ciphertext, mb_substr($key, 32, null, self :: ENCODING), true);

        return $hmac . $iv . $ciphertext;
    }
1143769
public function encrypt(string $data): string
    {
        try {
            return Crypto::encrypt($data, $this->key);
        } catch(EnvironmentIsBrokenException $e) {
            throw new CryptoException($e->getMessage(), $e->getCode(), $e);
        }
    }
978757
public function decrypt(string $data)
    {
        $this->throwExceptionIfKeyEmpty();

        if ($data === '') {
            return '';
        }

        list($encrypted_data, $iv) = \explode('::', \base64_decode($data, true), 2);

        return \openssl_decrypt($encrypted_data, $this->method, $this->key, 0, $iv);
    }