首页 > 代码库 > byte与base64字串换转

byte与base64字串换转

public byte[] base64ToByte(String strBase64){
  if(strBase64==null)return null;
  byte[] bytes = null;
  try {
  BASE64Decoder dec = new BASE64Decoder();
  bytes = dec.decodeBuffer(strBase64);
  }
  catch(Exception ex){
  ex.printStackTrace();
  }
  return bytes;
}

 

public String byteToBase64(byte[] aryByte){
  if(aryByte==null)return "";
    String strBase64 = "";
  try {
    BASE64Encoder enc = new BASE64Encoder();
    strBase64 = enc.encode(aryByte);
  }
  catch(Exception ex){
    ex.printStackTrace();
  }
  return strBase64;
}

byte与base64字串换转