/** * returns length of decoded data given an * array containing encoded data. * WhiteSpace removing is done if data array not * valid. * * @param base64Data an array containing encoded data * @return length of decoded data, -1 if not decoded */ public static synchronized int getDecodedDataLength(byte[] base64Data) { if (base64Data == null) { return -1; } if (base64Data.length == 0) { return 0; } //byte[] normalizedBase64Data = removeWhiteSpace( base64Data );//Remove any whiteSpace byte[] decodedData = null; if ((decodedData = decode(base64Data)) == null) { //decode could return a null byte array return -1; } return decodedData.length; } }
/** * returns length of decoded data given an * array containing encoded data. * WhiteSpace removing is done if data array not * valid. * * @param base64Data an array containing encoded data * @return length of decoded data, -1 if not decoded */ public static synchronized int getDecodedDataLength(byte[] base64Data) { if (base64Data == null) { return -1; } if (base64Data.length == 0) { return 0; } //byte[] normalizedBase64Data = removeWhiteSpace( base64Data );//Remove any whiteSpace byte[] decodedData = null; if ((decodedData = decode(base64Data)) == null) { //decode could return a null byte array return -1; } return decodedData.length; } }
/** * Decrypts given encrypted variable. * * @param encryptedStr * @return */ protected String decrypt(String encryptedStr) throws Exception { String[] split = encryptedStr.split(":"); checkTrue(split.length == 3, "Wrong format of the encrypted variable (" + encryptedStr + ")"); byte[] salt = Base64.decode(split[0].getBytes(UTF8_CHARSET)); checkTrue(salt.length == saltLengthBytes, "Salt length doesn't match."); int iterations = Integer.parseInt(split[1]); byte[] encryptedVal = Base64.decode(split[2].getBytes(UTF8_CHARSET)); return new String(transform(Cipher.DECRYPT_MODE, encryptedVal, salt, iterations), UTF8_CHARSET); }
/** * Decrypts given encrypted variable. * * @param encryptedStr * @return */ protected String decrypt(String encryptedStr) throws Exception { String[] split = encryptedStr.split(":"); checkTrue(split.length == 3, "Wrong format of the encrypted variable (" + encryptedStr + ")"); byte[] salt = Base64.decode(split[0].getBytes(UTF8_CHARSET)); checkTrue(salt.length == saltLengthBytes, "Salt length doesn't match."); int iterations = Integer.parseInt(split[1]); byte[] encryptedVal = Base64.decode(split[2].getBytes(UTF8_CHARSET)); return new String(transform(Cipher.DECRYPT_MODE, encryptedVal, salt, iterations), UTF8_CHARSET); }