不好意思,没考虑中文 这样 public static String changeStr(String s) throws UnsupportedEncodingException { if(s == null) return ""; byte[] b = s.getBytes("utf-8"); return new String(b,"utf-8"); }[code=Java] public static void main(String[] args) { String s = "窝窝啊a12321"; try { System.out.println(changeStr(s)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }[/code]
public static String changeStr(byte[] b) { StringBuffer sb = new StringBuffer(1024); if(b == null) return ""; for (byte by : b) { if (by == 63) by = (byte) (by & 100000);//or (by >> 1)+1 sb.append((char)by); } return sb.toString(); }
StringBuffer sb = new StringBuffer(1024);
if(s == null)
return "";
byte[] b = s.getBytes();
for (byte by : b) {
if (by == 63)
by = (byte) (by & 100000);//or (by >> 1)+1
sb.append((char)by);
}
return sb.toString();
}
这样 public static String changeStr(String s) throws UnsupportedEncodingException {
if(s == null)
return "";
byte[] b = s.getBytes("utf-8");
return new String(b,"utf-8");
}[code=Java]
public static void main(String[] args) {
String s = "窝窝啊a12321";
try {
System.out.println(changeStr(s));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}[/code]
StringBuffer sb = new StringBuffer(1024);
if(b == null)
return "";
for (byte by : b) {
if (by == 63)
by = (byte) (by & 100000);//or (by >> 1)+1
sb.append((char)by);
}
return sb.toString();
}
throws UnsupportedEncodingException {
if (s == null)
return null;
return (new sun.misc.BASE64Encoder()).encode(s.getBytes("UTF-8"));
} // 把64bit编码转化成普通字符串
public static String Base64ToStr(String s) {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s); return new String(b, "UTF-8"); } catch (Exception e) {
return null;
}
}
lz的方式改变下,加密过程相当于直接用base64 encode,写到文件中,然后字符流读出的时候再做decode