public static String decodeInfo(String data)
{
String returnmsg = "";
try
{
if(isNotEmpty(data))
{
returnmsg = new String(decode(data),"GBK");
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
return returnmsg;
}
/**
*
* 判断data是否为空,如果为空返回false,不空为true
* @param data
* @return boolean
* 如果有违例,请使用@exception/throws [违例类型] [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
* @see [类、类#方法、类#成员]
*/
public static boolean isNotEmpty(String data)
{
boolean flag = false;
if (null != data)
{
data = data.trim();
//如果传输字符是空串返回false,不空返回true
flag = "".equals(data)?false:true;
}
return flag;
}
}
新建一个类进行测试:
public class TestBaseCode {
public static void main(String[] args) {
// TODO Auto-generated method stub
String telephone = Base64.decodeInfo("MTM1MDAzMzAwNjY=");//解密
String userName = Base64.decodeInfo("zfXPyMn6");
System.out.println(telephone);
System.out.println(userName);
String jiamiTelephone = "";
try {
byte[] data ="123465678".getBytes();
jiamiTelephone = new String(Base64.encode(data));//加密
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(jiamiTelephone);
}
}
{
String returnmsg = "";
try
{
if(isNotEmpty(data))
{
returnmsg = new String(decode(data),"GBK");
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
return returnmsg;
}
/**
*
* 判断data是否为空,如果为空返回false,不空为true
* @param data
* @return boolean
* 如果有违例,请使用@exception/throws [违例类型] [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
* @see [类、类#方法、类#成员]
*/
public static boolean isNotEmpty(String data)
{
boolean flag = false;
if (null != data)
{
data = data.trim();
//如果传输字符是空串返回false,不空返回true
flag = "".equals(data)?false:true;
}
return flag;
}
}
新建一个类进行测试:
public class TestBaseCode {
public static void main(String[] args) {
// TODO Auto-generated method stub
String telephone = Base64.decodeInfo("MTM1MDAzMzAwNjY=");//解密
String userName = Base64.decodeInfo("zfXPyMn6");
System.out.println(telephone);
System.out.println(userName);
String jiamiTelephone = "";
try {
byte[] data ="123465678".getBytes();
jiamiTelephone = new String(Base64.encode(data));//加密
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(jiamiTelephone);
}
}