Method which will encrypt a string.

@param clearText
Clear text to be encrypted.
@return Encrypted text.
@throws MissingParameterException
166395
public String encrypt(String clearText) throws MissingParameterException {

		if (StringUtils.isBlank(clearText)) {
			throw new MissingParameterException("Missing parameter: clearText");
		}

		return stringEncryptor.encrypt(clearText);
	}
480515
public String encrypt(String message) throws GeneralSecurityException {
		byte[] bytes = encryptor.encrypt(message.getBytes());
		return Base64.getEncoder().encodeToString(bytes);
	}
191782
public byte[] seal(byte[] plaintext) {
    final byte[] nonce = box.nonce(plaintext);
    final byte[] ciphertext = box.seal(nonce, plaintext);
    final byte[] combined = new byte[nonce.length + ciphertext.length];
    System.arraycopy(nonce, 0, combined, 0, nonce.length);
    System.arraycopy(ciphertext, 0, combined, nonce.length, ciphertext.length);
    return combined;
  }
1171215
protected String encrypt(String randomStr, String plainText) {
    ByteGroup byteCollector = new ByteGroup();
    byte[] randomStringBytes = randomStr.getBytes(CHARSET);
    byte[] plainTextBytes = plainText.getBytes(CHARSET);
    byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder(plainTextBytes.length);
    byte[] appIdBytes = appidOrCorpid.getBytes(CHARSET);

    // randomStr + networkBytesOrder + text + appid
    byteCollector.addBytes(randomStringBytes);
    byteCollector.addBytes(bytesOfSizeInNetworkOrder);
    byteCollector.addBytes(plainTextBytes);
    byteCollector.addBytes(appIdBytes);

    // ... + pad: 使用自定义的填充方式对明文进行补位填充
    byte[] padBytes = PKCS7Encoder.encode(byteCollector.size());
    byteCollector.addBytes(padBytes);

    // 获得最终的字节流, 未加密
    byte[] unencrypted = byteCollector.toBytes();

    try {
      // 设置加密模式为AES的CBC模式
      Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
      SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
      IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16);
      cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);

      // 加密
      byte[] encrypted = cipher.doFinal(unencrypted);

      // 使用BASE64对加密后的字符串进行编码
      String base64Encrypted = base64.encodeToString(encrypted);

      return base64Encrypted;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
264417
private static byte[] convertClearTextToByteArray(String clearText) {
        byte[] result = new byte[clearText.length() * 2];
        for (int i = 0; i < clearText.length(); i++) {
            char thisChar = clearText.charAt(i);
            int pos = i * 2;
            result[pos] = (byte) (thisChar >>> 8 & 0xFF);
            result[pos + 1] = (byte) (thisChar & 0xFF);
        }
        return result;
    }
225782
def encrypt(clear_text) -> str:
        
        if not isinstance(clear_text, bytes):
            clear_text = str.encode(clear_text)
        cipher = Fernet(current_app.config['KEY'])
        return cipher.encrypt(clear_text).decode("utf-8")
1333435
public static String encrypt(byte[] key256Bits, String plainText) {
        SecretKey secretKey = new SecretKeySpec(key256Bits, "AES");
        return encryptBouncyCastle(secretKey, plainText);
//        return encryptLegacyJavaSecurity(secretKey, plainText);
    }
693349
public byte[] encrypt(byte[] text, PublicKey key) throws MangooEncryptionException {
        Objects.requireNonNull(text, Required.PLAIN_TEXT.toString());
        Objects.requireNonNull(text, Required.PUBLIC_KEY.toString());
        
        byte[] encrypt = null;
        try {
            Cipher cipher = Cipher.getInstance(ENCRYPTION);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            encrypt = cipher.doFinal(text);
        } catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidKeyException e) {
            throw new MangooEncryptionException("Failed to encrypt clear text with public key", e);
        }

        return encrypt;
    }
117832
private String decrypt( final String maybeEncryptedPassphrase ) {
        if (maybeEncryptedPassphrase == null) {
            return null;
        }

        try {
            final String decrypted = secDispatcher.decrypt(maybeEncryptedPassphrase);
            if (maybeEncryptedPassphrase.equals(decrypted)) {
                console.info("Passphrase was not encrypted");
            } else {
                console.info("Passphrase was successfully decrypted");
            }
            return decrypted;
        } catch (SecDispatcherException e) {
            console.warn("Unable to decrypt passphrase: " + e.getMessage());
        }

        return maybeEncryptedPassphrase;
    }
1286647
@Override
    public String encryptPassword(String cleartext) {
        String encrypted = sha256Encryptor.encryptPassword(cleartext);
        if (encrypted.endsWith("\n")) {
            encrypted = encrypted.substring(0, encrypted.length() - 1);
        }
        encrypted = SHA256_PREFIX.concat(encrypted);
        return encrypted;
    }
116373
public static String decrypt(String encrypted) {
        try {
            return decrypt(encrypted, null);
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
            return null;
        }
    }
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;
    }
989179
public static String encrypt(String salt, String password, String plainText) {
        SecretKey secret = getKey(salt, password);
        return encryptBouncyCastle(secret, plainText);
    }
256130
public String decrypt(String encrytedText, String key) {
        Objects.requireNonNull(encrytedText, Required.ENCRYPTED_TEXT.toString());
        Objects.requireNonNull(key, Required.KEY.toString());

        CipherParameters cipherParameters = new ParametersWithRandom(new KeyParameter(getSizedSecret(key).getBytes(StandardCharsets.UTF_8)));
        this.paddedBufferedBlockCipher.init(false, cipherParameters);
        
        return new String(cipherData(base64Decoder.decode(encrytedText)), StandardCharsets.UTF_8);
    }
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$
    }
558288
public static byte[] decodeLines(final String text) {
       char[] buf = new char[text.length()];
       int pValue = 0;
       for (int ip = 0; ip < text.length(); ip++) {
           final char cValue = text.charAt(ip);
           if (cValue != ' ' && cValue != '\r' && cValue != '\n' && cValue != '\t') {
               buf[pValue++] = cValue;
           }
       }
       return decode(buf, 0, pValue);
   }
1145868
public String encrypt(String plainText) {
    // 加密
    String encryptedXml = encrypt(genRandomStr(), plainText);

    // 生成安全签名
    String timeStamp = timeStamp = Long.toString(System.currentTimeMillis() / 1000l);
    String nonce = genRandomStr();

    try {
      String signature = SHA1.gen(token, timeStamp, nonce, encryptedXml);
      String result = generateXml(encryptedXml, signature, timeStamp, nonce);
      return result;
    } catch (NoSuchAlgorithmException e) {
      throw new RuntimeException(e);
    }
  }