This method encrypts a string using a shared key.

@param sharedKey The shared key used for the encryption.
@param string The string to be encrypted.
@return The encrypted string.
486045
public final byte[] encryptString(SecretKey sharedKey, String string) {
        logger.entry();
        try (ByteArrayInputStream input = new ByteArrayInputStream(string.getBytes("UTF-8"));
                ByteArrayOutputStream output = new ByteArrayOutputStream()) {
            encryptStream(sharedKey, input, output);
            output.flush();
            byte[] encryptedString = output.toByteArray();
            logger.exit();
            return encryptedString;
        } catch (IOException e) {
            // should never happen!
            RuntimeException exception = new RuntimeException("An unexpected exception occured while trying to encrypt a string.", e);
            logger.error(exception.toString());
            throw exception;
        }
    }
341226
public static String encryptData(String data, String key) throws Exception {
		// 创建密码器
		Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
		// 初始化
		cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(HashKit.md5(key).toLowerCase().getBytes(), ALGORITHM));
		return Base64Kit.encode(cipher.doFinal(data.getBytes()));
	}
895567
public static byte[] encrypt(byte[] contentByteArray, PublicKey publicKey) {
        try {
            Cipher cipher = Cipher.getInstance(algorithm);
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            return cipher.doFinal(contentByteArray);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        }
        return null;
    }
1074200
protected function encrypt($string)
    {
        $iv = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher, $this->cipherMode), MCRYPT_RAND);

        return mcrypt_encrypt($this->cipher, $this->secretKey, $string, $this->cipherMode, $iv);
    }
983985
final public static function encrypt(string $plainText, string $key = null, string $method = null): string
    {
        if ($method === null) {
            $method = static::getMethod();

            if (!in_array($method, openssl_get_cipher_methods())) {
                throw new CryptException("OpenSSL method={$method} defined in application config is not available");
            }
        } else {
            if (!in_array($method, openssl_get_cipher_methods())) {
                throw new CryptException("Passed OpenSSL method={$method} is not available");
            }
        }

        $key = Util::str2hex($key ?? Application::getKey());
        $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));

        $encrypted = @openssl_encrypt($plainText, $method, $key, 0, $iv);

        if ($encrypted === false) {
            throw new CryptException('Unable to encrypt your plain text; check your openssl_default_method in application config');
        }

        return $encrypted . ':' . bin2hex($iv);
    }
1011892
public static function des($string, $key, $operation = self::ENCRYPT) {
        if ($operation === static::ENCRYPT) {
            return static::encrypt($string, $key, static::DES);
        } else {
            return static::decrypt($string, $key, static::DES);
        }
    }
480515
public String encrypt(String message) throws GeneralSecurityException {
		byte[] bytes = encryptor.encrypt(message.getBytes());
		return Base64.getEncoder().encodeToString(bytes);
	}
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'];
    }
1363511
public static String encrypt(String input, String strkey)
    throws GeneralSecurityException {
        SecretKey key;
        if (strkey != null) {
            if (strkey.length() > 56)
                strkey = strkey.substring(0, 55);
            key = new SecretKeySpec(strkey.getBytes(), algorithm);
        }
        else {
            if (defaultKey==null) defaultKey =
                new SecretKeySpec(defaultKeyString.getBytes(), algorithm);
            key = defaultKey;
        }
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] inputBytes = input.getBytes();
        byte[] encrypted = cipher.doFinal(inputBytes);
        return encodeAlpha(encrypted);
    }
620127
public void encrypt(final String userName, final String password) {
        encrypt(userName, password.getBytes(Charsets.UTF_8), MessageEncryption.NONE);
    }
1133757
public PrivateKey getPrivateKeyFromString(String key) throws MangooEncryptionException {
        Objects.requireNonNull(key, Required.KEY.toString());
        
        try {
            return KeyFactory.getInstance(ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(decodeBase64(key)));
        } catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
            throw new MangooEncryptionException("Failed to get private key from string", e);
        }
    }
396951
public Key generateSharedKey() throws KeyException {
        javax.crypto.spec.SecretKeySpec sharedKey = null;
        try {
            if (crypto != null) {
                sharedKey = new javax.crypto.spec.SecretKeySpec(crypto.generate3DESKey(), 0, 24, "3DES");
            }

            if (sharedKey != null) {
                return sharedKey;
            } else {
                throw new com.ibm.websphere.crypto.KeyException("Key could not be generated.");
            }

        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ws.security.audit.AuditEncryptionImpl.generateKey", "98", this);
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Error generating key.", new Object[] { e });

            if (e instanceof KeyException)
                throw (KeyException) e;
            else
                throw new KeyException(e.getMessage(), e);
        }
    }
1009343
public static String xor(String string, String key) {
        return xor(string, CryptUtils.stringToKey(string));
    }
1360101
protected function encrypt(string $string)
    {
        $pub_key = openssl_pkey_get_public($this->getRsaKey($this->pub_key));

        $length = openssl_pkey_get_details($pub_key)['bits'];

        $string = str_split($string, $length / 8 - 11);
        $encryptedString = '';

        foreach ($string as $value) {
            openssl_public_encrypt($value, $encrypted, $pub_key);
            $encryptedString .= $encrypted;
        }

        return base64_encode($encryptedString);
    }
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;
    }
487123
public static String encrypt(String str) {
	if (StringUtil.isEmpty(str)) return "";
	if (StringUtil.startsWithIgnoreCase(str, "encrypted:")) return str;
	return "encrypted:" + new BlowfishEasy("sdfsdfs").encryptString(str);
    }
1153503
public static function decrypt(
        string $ciphertext,
        SharedEncryptionKey $key
    ): string {
        $nonce = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 24);
        $result = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
            \ParagonIE_Sodium_Core_Util::substr($ciphertext, 24),
            $nonce,
            $nonce,
            $key->getString(true)
        );
        if (!\is_string($result)) {
            throw new InvalidMessageException('Message authentication failed.');
        }
        return $result;
    }