You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Base64Util.java 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.educoder.bridge.utils;
  2. import org.apache.commons.codec.binary.Base64;
  3. import java.nio.charset.StandardCharsets;
  4. /**
  5. * Created by guange on 23/02/2017.
  6. */
  7. public class Base64Util {
  8. /**
  9. * base64编码
  10. *
  11. * @param code
  12. * @return
  13. */
  14. public static String encode(String code) {
  15. byte[] encode = Base64.encodeBase64URLSafe(code.getBytes(StandardCharsets.UTF_8));
  16. return new String(encode, StandardCharsets.UTF_8);
  17. }
  18. public static byte[] encodeBytes(byte[] codes) {
  19. return Base64.encodeBase64(codes);
  20. }
  21. /**
  22. * base64解码
  23. *
  24. * @param code
  25. * @return
  26. */
  27. public static String decode(String code) {
  28. byte[] decode = Base64.decodeBase64(code);
  29. return new String(decode, StandardCharsets.UTF_8);
  30. }
  31. /**
  32. * base64再解码,把原本的非URL safe编码转换为URL safe编码
  33. *
  34. * @param code
  35. * @return
  36. */
  37. public static String reencode(String code) {
  38. String str = decode(code);
  39. str = str.replace("\n", "\r\n");
  40. return encode(str);
  41. }
  42. }

人工智能研发终端

Contributors (1)