征集数据加密的方式,本人现在还没有用过数据加密,请问一下,现在都有哪些加密方式?提供详细资料和例子!
------解决方案--------------------
MD5加密
- Java code
import java.security.MessageDigest;public class MD5_1 { public final static String MD5(String s){ char hexDigits[]={ '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' }; try{ byte[] strTemp=s.getBytes(); MessageDigest mdTemp=MessageDigest.getInstance("MD5"); mdTemp.update(strTemp); byte[] md=mdTemp.digest(); int j=md.length; char str[]=new char[j*2]; int k=0; for(int i=0;i<j;i++){ byte byte0 = md[i]; str[k++] = hexDigits[byte0 >>> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); }catch(Exception e){ e.printStackTrace(); return null; } }
------解决方案--------------------
- Java code
import java.util.HashMap;import java.util.Map;public class Ecrypt { public static int fgetps(String str) { Map s = new HashMap(); s.put("0", "124"); s.put("1", "99"); s.put("2", "75"); s.put("3", "65"); s.put("4", "445"); s.put("5", "367"); s.put("6", "313"); s.put("7", "271"); s.put("8", "239"); s.put("9", "211"); s.put("a", "183 "); s.put("b", "1115"); s.put("c", "1135"); s.put("d", "1157"); s.put("e", "1177"); s.put("f", "1505"); s.put("g", "1211"); s.put("h", "1321"); s.put("i", "1471"); s.put("j", "1110"); s.put("k", "1347"); s.put("l", "1112"); s.put("m", "1113"); s.put("n", "1114"); s.put("o", "1361"); s.put("p", "1116"); s.put("q", "1309"); s.put("r", "1347"); s.put("s", "1119"); s.put("t", "1389"); s.put("u", "1405"); s.put("v", "1425"); s.put("w", "1467"); s.put("x", "1219"); s.put("y", "1187"); s.put("z", "1151"); s.put("A", "83 "); s.put("B", "115"); s.put("C", "135"); s.put("D", "157"); s.put("E", "177"); s.put("F", "505"); s.put("G", "211"); s.put("H", "321"); s.put("I", "471"); s.put("J", "110"); s.put("K", "347"); s.put("L", "112"); s.put("M", "113"); s.put("N", "114"); s.put("O", "361"); s.put("P", "116"); s.put("Q", "309"); s.put("R", "347"); s.put("S", "119"); s.put("T", "389"); s.put("U", "405"); s.put("V", "425"); s.put("W", "467"); s.put("X", "219"); s.put("Y", "187"); s.put("Z", "151"); s.put("~", "431"); s.put("!", "363"); s.put("@", "397"); s.put("#", "331"); s.put("$", "293"); s.put("%", "251"); s.put("^", "239"); s.put("&", "223"); s.put("*", "189"); s.put("(", "165"); s.put(")", "153"); s.put("-", "142"); s.put("+", "609"); s.put("|", "577"); s.put("\\", "547"); s.put("/", "511"); s.put("*", "493"); s.put(".", "327"); s.put(",", "285"); s.put(";", "267"); s.put("{", "251"); s.put("}", "223"); s.put("[", "122"); s.put("]", "634"); if (str == null) str = ""; String str1 = str.trim(); int max = str1.length(); int password = 0; String str2 = ""; String str3 = ""; for (int i = 0; i < max; i++) { str2 = str1.substring(i, i + 1); str3 = (String) s.get(str2); if (str3 != null) password += Integer.parseInt(str3); } return password; }