请问java里将某个文本进行加密成了6位的数字+字母,请问是什么加密方式,加密成的值字母区分大小写。

如题所述

第1个回答  2011-03-15
这个加密不知道行不行?
public class Escape {
private final static String[] hex = { "00", "01", "02", "03", "04", "05",
"06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B",
"1C", "1D", "1E", "1F", "20", "21", "22", "23", "24", "25", "26",
"27", "28", "29", "2A", "2B", "2C", "2D", "2E", "2F", "30", "31",
"32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B", "3C",
"3D", "3E", "3F", "40", "41", "42", "43", "44", "45", "46", "47",
"48", "49", "4A", "4B", "4C", "4D", "4E", "4F", "50", "51", "52",
"53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "5D",
"5E", "5F", "60", "61", "62", "63", "64", "65", "66", "67", "68",
"69", "6A", "6B", "6C", "6D", "6E", "6F", "70", "71", "72", "73",
"74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", "7E",
"7F", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
"8A", "8B", "8C", "8D", "8E", "8F", "90", "91", "92", "93", "94",
"95", "96", "97", "98", "99", "9A", "9B", "9C", "9D", "9E", "9F",
"A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA",
"AB", "AC", "AD", "AE", "AF", "B0", "B1", "B2", "B3", "B4", "B5",
"B6", "B7", "B8", "B9", "BA", "BB", "BC", "BD", "BE", "BF", "C0",
"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB",
"CC", "CD", "CE", "CF", "D0", "D1", "D2", "D3", "D4", "D5", "D6",
"D7", "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF", "E0", "E1",
"E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "EB", "EC",
"ED", "EE", "EF", "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
"F8", "F9", "FA", "F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x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F };

/**
* Unicode 格式 编码
*
* @param s
* @return
*/
public static String escape(String s) {
StringBuffer sbuf = new StringBuffer();
int len = s.length();
for (int i = 0; i < len; i++) {
int ch = s.charAt(i);
if ('A' <= ch && ch <= 'Z') {
sbuf.append((char) ch);
} else if ('a' <= ch && ch <= 'z') {
sbuf.append((char) ch);
} else if ('0' <= ch && ch <= '9') {
sbuf.append((char) ch);
} else if (ch == '-' || ch == '_'
|| ch == '.' || ch == '!' || ch == '~' || ch == '*'
|| ch == '\'' || ch == '(' || ch == ')') {
sbuf.append((char) ch);
} else if (ch <= 0x007F) {
sbuf.append('%');
sbuf.append(hex[ch]);
} else {
sbuf.append('%');
sbuf.append('u');
sbuf.append(hex[(ch >>> 8)]);
sbuf.append(hex[(0x00FF & ch)]);
}
}
return sbuf.toString();
}

/**
* 解码 说明:本方法保证 不论参数s是否经过escape()编码,均能得到正确的“解码”结果
*
* @param s
* @return
*/
public static String unescape(String s) {
StringBuffer sbuf = new StringBuffer();
int i = 0;
int len = s.length();
while (i < len) {
int ch = s.charAt(i);
if ('A' <= ch && ch <= 'Z') {
sbuf.append((char) ch);
} else if ('a' <= ch && ch <= 'z') {
sbuf.append((char) ch);
} else if ('0' <= ch && ch<= '9') {
sbuf.append((char) ch);
} else if (ch == '-' || ch == '_'|| ch == '.' || ch == '!' || ch == '~' || ch == '*'|| ch == '\'' || ch == '(' || ch == ')') {
sbuf.append((char) ch);
} else if (ch == '%') {
int cint = 0;
if ('u' != s.charAt(i + 1)) {
cint = (cint << 4) | val[s.charAt(i + 1)];
cint = (cint << 4) | val[s.charAt(i + 2)];
i += 2;
} else {
cint = (cint << 4) | val[s.charAt(i + 2)];
cint = (cint << 4) | val[s.charAt(i + 3)];
cint = (cint << 4) | val[s.charAt(i + 4)];
cint = (cint << 4) | val[s.charAt(i + 5)];
i += 5;
}
sbuf.append((char) cint);
} else {
sbuf.append((char) ch);
}
i++;
}
return sbuf.toString();
}
/**
* 把unicode编码转换成正常字符
*
* @param hex
* @return
*/
public static String binaryToUnicode(String hex) {
String strContent = "";
try {
int i;
int n;
int j;
n = hex.length() / 4;
j = 0;
char[] content = new char[n];
for (i = 0; i < n; i++) {
j = i * 4;
content[i] = (char) Integer.parseInt(hex.substring(j, j + 4),
16);
}
strContent = new String(content);
} catch (Exception ex) {
ex.printStackTrace();
strContent = "";
}
return strContent;
}

/**
* 把字符转换成unicode编码
*
* @param content
* @return
*/
public static String unicodeToBinary(String content) {
String hexStr = "";

try {
char[] contentBuffer = content.toCharArray();
String s;
int n;

for (int i = 0; i < content.length(); i++) {
n = (int) contentBuffer[i];
s = Integer.toHexString(n);

if (s.length() > 4) {
s = s.substring(0, 4);
} else {
s = "0000".substring(0, 4 - s.length()) + s;
}

hexStr = hexStr + s;
}
} catch (Exception ex) {
hexStr = "";
}

return hexStr.toUpperCase();
}

public static void main(String[] args) {
// String stest = "\"asd请选择";
// System.out.println(escape(stest));
// System.out.println(unescape(escape(stest))+"||"+unescape(stest));
// System.out.println("0----9:"+(int)'0'+"--------"+(int)'9');
// System.out.println("A----Z:"+(int)'A'+"--------"+(int)'Z');
// System.out.println("a----z:"+(int)'a'+"--------"+(int)'z');
// System.out.println("-:"+(int)'-'+"||" +(int)'_'+"||"+(int)'.'
// +"||" +(int)'!'+"||"
// +(int)'~'+"||"+(int)'*'+"||"+(int)'\''+"||"
// +(int)'('+"||"+(int)')'+"||");
// for (int i = 0; i < 128; i++) {
// if (i%10==0) {
// System.out.print(" "+i+"="+(char)i+"\n");
// }else{
// System.out.print(" "+i+"="+(char)i);
// }
// // char ch = (char)i;
// // if (ch == '-' || ch == '_'|| ch == '.' || ch == '!' || ch == '~' || ch == '*'|| ch == '\'' || ch == '(' || ch == ')') {
// // System.out.println(ch+"="+(int)ch+" ");
// // }
// }unescape(String s)
System.out.println(Escape.unescape("撒33范德萨"));
System.out.println(Escape.unicodeToBinary("战略绩效计划调整"));
System.out.println(Escape.binaryToUnicode("621875657EE965488BA152128C036574"));
System.out.println(Escape.unescape("%u6492%u8303%u5FB7%u8428%u9426"));
}
}追问

请问可以帮我做成一个加密和一个解密的界面吗?ASPX的

本回答被提问者采纳

请问java里将某个文本进行加密成了6位的数字+字母,请问是什么加密方式...
"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF", "E0", "E1", "E2", "E3", "...

java 请问这是什么加密算法?
1、这是一个对称加密算法

java 加密方式有哪些
1. 对称加密:对称加密是指加密和解密使用相同密钥的加密方式。在Java中,常见的对称加密算法有AES、DES、3DES等。其中,AES算法是DES的替代品,具有更高的安全性。这些算法提供了不同级别的加密强度,适用于保护敏感信息。2. 非对称加密:非对称加密使用一对密钥,一个用于加密,另一个用于解密。在Java...

JAVA使用什么加密算法和解密算法好
简单的Java加密算法有:第一种. BASE Base是网络上最常见的用于传输Bit字节代码的编码方式之一,大家可以查看RFC~RFC,上面有MIME的详细规范。Base编码可用于在HTTP环境下传递较长的标识信息。例如,在Java Persistence系统Hibernate中,就采用了Base来将一个较长的唯一标识符(一般为-bit的UUID)编码为一...

java加密的几种方式
复杂的对称加密(DES、PBE)、非对称加密算法:DES(Data Encryption Standard,数据加密算法)PBE(Password-based encryption,基于密码验证)RSA(算法的名字以发明者的名字命名:Ron Rivest, AdiShamir 和Leonard Adleman)DH(Diffie-Hellman算法,密钥一致协议)DSA(Digital Signature Algorithm,数字签名)ECC(...

java怎么将一个六位数拆成六个一位数进行加密解密
如果你是 String a ="123456";你就用char c = a.charAt(0-5);把每个字符取出来减去字符0,就是对应的数字了

Java 编写加密类,实现对输入字符串进行加密,加密算法如下: 1.每个字符...
public static String encrypt(String str){ StringBuilder sb=new StringBuilder(str);for(int i=0;i<sb.length();i++){ char c=sb.charAt(i);sb.setCharAt(i,(char)(c+i));} sb.reverse();return sb.toString();} public static void main(String[] args) { String s="abc";s=...

请问用java如何对文件进行加密解密?
\/** * 加密--把加密后的byte数组先进行二进制转16进制在进行base64编码 * @param sSrc * @param sKey * @return * @throws Exception *\/ public static String encrypt(String sSrc, String sKey) throws Exception { if (sKey == null) { throw new IllegalArgume...

JavaMD5和SHA256等常用加密算法
其中AES后面的数字代表的是密钥长度。对称加密算法的安全性相对较低,比较适用的场景就是内网环境中的加解密。所谓对称加密,就是通过密钥加密后可以再通过密钥解密。我接触过的某个国企现在内部就是采用AES的方式实现集成登陆。第三方系统提供一个接收用户信息的接口,该国企将用户信息AES加密后通过这个接口...

文本被加密了,如何解密.
比如 "我" 这个字的ascii码是\我,加1移位成\戒(戒),这样一片文章就面目全非了.当然移位成什么看你自己的移位算法,然后再转成汉字写回去.package test;import java.io.IOException;public class Native2ascii { private static final String java_path = "G:\\\\Java\\\\jdk 1.6";\/\/你的...

相似回答