Class Base64Encoder

    • Constructor Detail

      • Base64Encoder

        public Base64Encoder()
    • Method Detail

      • encode

        public static void encode​(InputStream in,
                                  OutputStream out)
                           throws IOException
        Encodes data from supplied input to output.
        Parameters:
        in - The input stream to be encoded.
        out - The output stream, to write encoded data to.
        Throws:
        IOException
      • encode

        public static void encode​(byte[] input,
                                  OutputStream out)
                           throws IOException
        Encode the supplied byte array and write the encoded data to the OutputStream out.
        Throws:
        IOException
      • encode

        public static String encode​(String input)
                             throws IOException
        Encode the given string,and return the encoded version as a string.
        Returns:
        A String, representing the encoded content of the input String.
        Throws:
        IOException
      • encode

        public static String encode​(byte[] bytes)
                             throws IOException
        Encode the given byte array and return the result as a string.
        Throws:
        IOException
      • main

        public static void main​(String[] args)
                         throws Exception
        Run with one argument, prints the encoded version of it. With two, the second is assumed to be the name of a MessageDigest to be applied to the string before encoding (useful for generating password hashes).

        Alternatively, use the openssl utility, for example:

        echo -n "password" | openssl dgst -sha1 -binary | openssl base64

        Throws:
        Exception