org.springframework.util

Class Base64Utils

  • java.lang.Object
    • org.springframework.util.Base64Utils


  • public abstract class Base64Utils
    extends java.lang.Object
    A simple utility class for Base64 encoding and decoding.

    Adapts to Java 8's Base64 in a convenience fashion.

    Since:
    4.1
    Author:
    Juergen Hoeller, Gary Russell
    See Also:
    Base64
    • Constructor Summary

      Constructors 
      Constructor and Description
      Base64Utils() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static byte[] decode(byte[] src)
      Base64-decode the given byte array.
      static byte[] decodeFromString(java.lang.String src)
      Base64-decode the given byte array from an UTF-8 String.
      static byte[] decodeFromUrlSafeString(java.lang.String src)
      Base64-decode the given byte array from an UTF-8 String using the RFC 4648 "URL and Filename Safe Alphabet".
      static byte[] decodeUrlSafe(byte[] src)
      Base64-decode the given byte array using the RFC 4648 "URL and Filename Safe Alphabet".
      static byte[] encode(byte[] src)
      Base64-encode the given byte array.
      static java.lang.String encodeToString(byte[] src)
      Base64-encode the given byte array to a String.
      static java.lang.String encodeToUrlSafeString(byte[] src)
      Base64-encode the given byte array to a String using the RFC 4648 "URL and Filename Safe Alphabet".
      static byte[] encodeUrlSafe(byte[] src)
      Base64-encode the given byte array using the RFC 4648 "URL and Filename Safe Alphabet".
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Base64Utils

        public Base64Utils()
    • Method Detail

      • encode

        public static byte[] encode(byte[] src)
        Base64-encode the given byte array.
        Parameters:
        src - the original byte array
        Returns:
        the encoded byte array
      • decode

        public static byte[] decode(byte[] src)
        Base64-decode the given byte array.
        Parameters:
        src - the encoded byte array
        Returns:
        the original byte array
      • encodeUrlSafe

        public static byte[] encodeUrlSafe(byte[] src)
        Base64-encode the given byte array using the RFC 4648 "URL and Filename Safe Alphabet".
        Parameters:
        src - the original byte array
        Returns:
        the encoded byte array
        Since:
        4.2.4
      • decodeUrlSafe

        public static byte[] decodeUrlSafe(byte[] src)
        Base64-decode the given byte array using the RFC 4648 "URL and Filename Safe Alphabet".
        Parameters:
        src - the encoded byte array
        Returns:
        the original byte array
        Since:
        4.2.4
      • encodeToString

        public static java.lang.String encodeToString(byte[] src)
        Base64-encode the given byte array to a String.
        Parameters:
        src - the original byte array (may be null)
        Returns:
        the encoded byte array as a UTF-8 String
      • decodeFromString

        public static byte[] decodeFromString(java.lang.String src)
        Base64-decode the given byte array from an UTF-8 String.
        Parameters:
        src - the encoded UTF-8 String
        Returns:
        the original byte array
      • encodeToUrlSafeString

        public static java.lang.String encodeToUrlSafeString(byte[] src)
        Base64-encode the given byte array to a String using the RFC 4648 "URL and Filename Safe Alphabet".
        Parameters:
        src - the original byte array
        Returns:
        the encoded byte array as a UTF-8 String
      • decodeFromUrlSafeString

        public static byte[] decodeFromUrlSafeString(java.lang.String src)
        Base64-decode the given byte array from an UTF-8 String using the RFC 4648 "URL and Filename Safe Alphabet".
        Parameters:
        src - the encoded UTF-8 String
        Returns:
        the original byte array