Base64Utils.java 937 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.goafanti.common.utils;
  2. import java.io.UnsupportedEncodingException;
  3. import org.apache.commons.codec.binary.Base64;
  4. public class Base64Utils {
  5. public static String decodeData(String inputData) {
  6. try {
  7. if (null == inputData) {
  8. return null;
  9. }
  10. return new String(Base64.decodeBase64(inputData.getBytes("utf-8")), "utf-8");
  11. } catch (UnsupportedEncodingException e) {
  12. }
  13. return null;
  14. }
  15. /**
  16. * 对给定的字符串进行base64加密操作
  17. */
  18. public static String encodeData(String inputData) {
  19. try {
  20. if (null == inputData) {
  21. return null;
  22. }
  23. return new String(Base64.encodeBase64(inputData.getBytes("utf-8")), "utf-8");
  24. } catch (UnsupportedEncodingException e) {
  25. }
  26. return null;
  27. }
  28. }