Encrypt a text using public key. The result is encoded to Base64.

@param text The plain text
@param key The public key

@return Encrypted string as base64
@throws MangooEncryptionException if encryption fails
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;
    }
604072
public synchronized String encryptText(String text) {
		
		try {
			// Mise en mode Encrypt
			cipher.init(Cipher.ENCRYPT_MODE, this.createDESSecretKey(stringKey));
			
			// Obtention des bytes
			byte[] byteText = text.getBytes();
			
			// Encodage
			byte[] encodedByteText = cipher.doFinal(byteText);
			
			// Retour de la chaine encodee
			return new Base64().encodeToString(encodedByteText);
			
		} catch (Exception e) {
			
			// On relance l'exception
			throw new RuntimeException(e);
		}
	}
658771
public String decrypt(String text, PrivateKey key) throws MangooEncryptionException {
        Objects.requireNonNull(text, Required.ENCRYPTED_TEXT.toString());
        Objects.requireNonNull(text, Required.PRIVATE_KEY.toString());
        
        String decrypt = null;
        try {
            byte[] dectyptedText = decrypt(decodeBase64(text), key);
            decrypt = new String(dectyptedText, StandardCharsets.UTF_8);
        } catch (MangooEncryptionException e) {
            throw new MangooEncryptionException("Failed to decrypt encrypted text with private key", e);
        }

        return decrypt;
    }
1116894
def encrypt(plain)
      fail ArgumentError, 'No plain text supplied.' if plain.nil? || plain.empty?

      cipher = self.class.cipher
      cipher.encrypt
      cipher.key = Base64.decode64(@key)
      cipher.iv = iv = cipher.random_iv
      encrypted = cipher.update(plain)
      encrypted << cipher.final

      iv = Base64.strict_encode64(iv)
      encrypted = Base64.strict_encode64(encrypted)

      "$#{iv}$#{encrypted}"
    end
166395
public String encrypt(String clearText) throws MissingParameterException {

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

		return stringEncryptor.encrypt(clearText);
	}
695779
public static String decryptData(String base64Data, String key) throws Exception {
		Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
		cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(HashKit.md5(key).toLowerCase().getBytes(), ALGORITHM));
		return new String(cipher.doFinal(Base64Kit.decode(base64Data)));
	}
998563
public String decrypt64( final String encryptedText, final String password )
    throws PlexusCipherException
    {
        try
        {
            byte[] allEncryptedBytes = Base64.decodeBase64( encryptedText.getBytes() );
            
            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( password.getBytes( STRING_ENCODING ), salt, Cipher.DECRYPT_MODE  );
    
            byte [] clearBytes = cipher.doFinal( encryptedBytes );
            
            String clearText = new String( clearBytes, STRING_ENCODING ); 
    
            return clearText;
        }
        catch( Exception e)
        {
            throw new PlexusCipherException(e);
        }
    }
784894
public static String encrypt(String input) {
        byte[] result = encrypt(input.getBytes());
        return new String(result);
    }
1142072
public synchronized String encrypt(String plainText) {
        assertArgumentNotNull("plainText", plainText);
        if (encryptingCipher == null) {
            initialize();
        }
        return new String(encodeHex(doEncrypt(plainText)));
    }
85811
public static byte[] encryptAES2Base64(byte[] data, byte[] key) {
        try {
            return Base64.getEncoder().encode(encryptAES(data, key));
        } catch (Exception e) {
            return null;
        }
    }
1247331
def encrypt(text, key=None):
    
    if key is None:
        key = ENCRYPT_KEY

    bits = len(key)
    text = pad(text, bits)
    iv = Random.new().read(16)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    return base64.b64encode(iv + cipher.encrypt(text))
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);
    }
516012
@Override
  public String decrypt(String cipherText) {
    this.decryptionLock.lock();
    try{
      String decryptedValue = null;
      try {
        byte[] bytes = Base64.getDecoder().decode(cipherText);
        decryptedValue = new String(decryptCipher.doFinal(bytes), charset);
      } catch (UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e) {
        logger.error("DefaultAESCBCCipher failed to decrypt text", e);
        throw new JsonDBException("DefaultAESCBCCipher failed to decrypt text", e);
      }
      return decryptedValue;
    } finally{
      this.decryptionLock.unlock();
    }
  }
416566
def decrypt(text, key=None):
    
    if key is None:
        key = ENCRYPT_KEY

    bits = len(key)
    text = base64.b64decode(text)
    iv = text[:16]
    cipher = AES.new(key, AES.MODE_CBC, iv)
    return unpad(cipher.decrypt(text[16:]))
651249
public static byte[] decode(String key) {
		return Validator.isHex(key) ? HexUtil.decodeHex(key) : Base64.decode(key);
	}
925096
public static String decryptToBase64(String content) {
        byte[] decodedValue = DatatypeConverter.parseBase64Binary(content);
        return new String(decodedValue, CHARSET);
    }
301951
public static String encodeText(String text, Charset charset) {
		try {
			return MimeUtility.encodeText(text, charset.name(), null);
		} catch (UnsupportedEncodingException e) {
			// ignore
		}
		return text;
	}