293133e40567ed579b2263301c31fbaef564e507.svn-base 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.toolkit.DES;
  2. import org.apache.commons.codec.binary.Base64;
  3. /**
  4. * base64编解码类
  5. *
  6. * @author 刘东升
  7. * @version 1.0
  8. */
  9. public class base64{
  10. /**
  11. * 给定字节数组编码成base64的字符串
  12. *
  13. * @param s
  14. * 字节数组
  15. * @return 字符串
  16. */
  17. public static String getBASE64(byte[] s) {
  18. if (s == null)
  19. return null;
  20. byte[] tmp = null;
  21. Base64 b64 = new Base64();
  22. try {
  23. tmp = b64.encode(s);
  24. String a = new String(tmp);
  25. return a;
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. } finally {
  29. }
  30. return null;
  31. }
  32. /**
  33. * 给定一个字符串返回Base64解码的字节数组
  34. *
  35. * @param s
  36. * 字符串
  37. * @return 字节数组
  38. */
  39. public static byte[] getDeBASE64(String s) {
  40. if (s == null)
  41. return null;
  42. byte[] tmp = null;
  43. Base64 b64 = new Base64();
  44. try {
  45. tmp = b64.decode(s.getBytes());
  46. return tmp;
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. } finally {
  50. }
  51. return null;
  52. }
  53. }