public static byte [ ] decodeBase64 ( String encodedData ) { BufferedReader reader = new BufferedReader ( new StringReader ( encodedData ) ) ; int length = encodedData . length ( ) ; byte [ ] retval = new byte [ length ] ; int actualLength = 0 ; String line ; try { while ( ( line = reader . readLine ( ) ) != null ) { byte [ ] rawData = line . getBytes ( ) ; int n = 0 ; for ( int i = 0 ; i < rawData . length ; i += 4 ) { n = ( base64Chars . indexOf ( rawData [ i ] ) << 18 ) | ( base64Chars . indexOf ( rawData [ i + 1 ] ) << 12 ) ; retval [ actualLength ++ ] = ( byte ) ( ( n >>> 16 ) & 255 ) ; if ( rawData [ i + 2 ] != ' ' ) { n |= ( base64Chars . indexOf ( rawData [ i + 2 ] ) << 6 ) ; retval [ actualLength ++ ] = ( byte ) ( ( n >>> 8 ) & 255 ) ; } if ( rawData [ i + 3 ] != ' ' ) { n |= ( base64Chars . indexOf ( rawData [ i + 3 ] ) ) ; retval [ actualLength ++ ] = ( byte ) ( n & 255 ) ; } } } } catch ( IOException ioe ) { throw new IllegalStateException ( "exception while reading input with message: " + ioe ) ; } if ( actualLength != length ) { byte [ ] actualRetval = new byte [ actualLength ] ; System . arraycopy ( retval , 0 , actualRetval , 0 , actualLength ) ; return actualRetval ; } return retval ; }
Decodes base 64 encoded string .