/** Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with * and without line separators. * @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception. * @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(byte[] sArr) { return decode(sArr, 0, sArr.length); }
/** * Takes a encrypted String as an argument, decrypts and returns the decrypted String. * * @param str Encrypted String to be decrypted * @return <code>String</code> Decrypted version of the provided String */ public String decrypt(String str) { try { // Decode base64 to get bytes byte[] dec = Base64.decode(str); // Decrypt byte[] utf8 = dcipher.doFinal(dec); // Decode using utf-8 return new String(utf8, "UTF8"); } catch (Exception e) { LOG.log(Level.WARNING, "Could not decrypt string", e); } return null; } }