@Override
    public String encrypt(String keyId, String str) throws EncryptException {
        if (str == null) {
            return null;
        }
        try {
            initCiphers();
            byte[] cleartext = str.getBytes("UTF-8");
            byte[] ciphertext = this.encryptCipher.doFinal(cleartext);
            return Base64.encodeBase64String(ciphertext);
        } catch (InvalidKeyException ex) {
            throw new AssertionError(ex);
        } catch (BadPaddingException | NoSuchPaddingException | IllegalBlockSizeException | NoSuchAlgorithmException ex) {
            throw new EncryptException("Could not encrypt string", ex);
        } catch (UnsupportedEncodingException ex) {
            throw new AssertionError("UTF-8 should be supported but is not");
        }
    }
@ Override public String encrypt ( String keyId , String str ) throws EncryptException { if ( str == null ) { return null ; } try { initCiphers ( ) ; byte [ ] cleartext = str . getBytes ( "UTF-8" ) ; byte [ ] ciphertext = this . encryptCipher . doFinal ( cleartext ) ; return Base64 . encodeBase64String ( ciphertext ) ; } catch ( InvalidKeyException ex ) { throw new AssertionError ( ex ) ; } catch ( BadPaddingException | NoSuchPaddingException | IllegalBlockSizeException | NoSuchAlgorithmException ex ) { throw new EncryptException ( "Could not encrypt string" , ex ) ; } catch ( UnsupportedEncodingException ex ) { throw new AssertionError ( "UTF-8 should be supported but is not" ) ; } }
Encrypts the provided string. This method applies the
DES/ECB/PKCS5Padding cipher and outputs the encrypted data as a hex
string. If an exception is thrown, this instance may no longer be usable.

@param str the string to encrypt.
@return the encrypted data as a hex string, or <code>null</code> if the
provided string is <code>null</code>.

@throws IllegalBlockSizeException if the provided string cannot be
encrypted.