md5工具使用方法(修改md5值的软件)
0x01:工具类md5加密工具类base64加密工具类Bcrypt工具类0x02:加密测试MD5加密测试base64加密测试SHA加密测试BCrypt加密测试0x03、工具类1. md5加密工具类public class MD5Utils {private static final String hexDigIts[] = {\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"};/** * MD5加密 * @param origin 字符 * @param charsetname 编码 * @return */public static String MD5Encode(String origin, String charsetname){ String resultString = null;try{ resultString = new String(origin); MessageDigest md = MessageDigest.getInstance(\"MD5\");if(null == charsetname || \"\".equals(charsetname)){ resultString = byteArrayToHexString(md.digest(resultString.getBytes())); }else{ resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname))); } }catch (Exception e){ }return resultString; }public static String byteArrayToHexString(byte b[]){ StringBuffer result = new StringBuffer();for(int i = 0; i < b.length; i++){ result.append(byteToHexString(b[i])); }return result.toString(); }public static String byteToHexString(byte b){int n = b;if(n < 0){ n += 256; }int d1 = n / 16;int d2 = n % 16;return hexDigIts[d1] + hexDigIts[d2]; }}2. base64加密工具类public class Base64Util {// 字符串编码private static final String UTF_8 = \"UTF-8\";/** * 加密字符串 * @param inputData * @return */public static String decodeData(String inputData) {try {if (null == inputData) {return null; }return new String(Base64.decodeBase64(inputData.getBytes(UTF_8)), UTF_8); } catch (UnsupportedEncodingException e) { }return null; }/** * 加密后的字符串 * @param inputData * @return */public static String encodeData(String inputData) {try {if (null == inputData) {return null; }return new String(Base64.encodeBase64(inputData.getBytes(UTF_8)), UTF_8); } catch (UnsupportedEncodingException e) { }return null; }public static void main(String[] args) { System.out.println(Base64Util.encodeData(\"我是中文\"));String enStr = Base64Util.encodeData(\"我是中文\"); System.out.println(Base64Util.decodeData(enStr)); }}3. Bcrypt工具类public class BcryptCipher {// generate salt seedprivate static final int SALT_SEED = 12;// the head fo saltprivate static final String SALT_STARTSWITH = \"$2a$12\";public static final String SALT_KEY = \"salt\";public static final String CIPHER_KEY = \"cipher\";/** * Bcrypt encryption algorithm method * @param encryptSource * need to encrypt the string * @return Map , two values in Map , salt and cipher */public static Map<String, String> Bcrypt(final String encryptSource) {String salt = BCrypt.gensalt(SALT_SEED); Map<String, String> bcryptResult = Bcrypt(salt, encryptSource);return bcryptResult; }/** * * @param salt encrypt salt, Must conform to the rules * @param encryptSource * @return */public static Map<String, String> Bcrypt(final String salt, final String encryptSource) {if (StringUtils.ilank(encryptSource)) {throw new RuntimeException(\"Bcrypt encrypt input params can not be empty\"); }if (StringUtils.ilank(salt) || salt.length() != 29) {throw new RuntimeException(\"Salt can\'t be empty and length must be to 29\"); }if (!salt.startsWith(SALT_STARTSWITH)) {throw new RuntimeException(\"Invalid salt version, salt version is $2a$12\"); }String cipher = BCrypt.hashpw(encryptSource, salt); Map<String, String> bcryptResult = new HashMap<String, String>(); bcryptResult.put(SALT_KEY, salt); bcryptResult.put(CIPHER_KEY, cipher);return bcryptResult; }}0x04:加密测试1. MD5加密测试/** * MD5加密 */public class MD5Test {public static void main(String[] args) { String string = \"我是一句话\"; String byteArrayToHexString = MD5Utils.byteArrayToHexString(string.getBytes()); System.out.println(byteArrayToHexString);//e68891e698afe4b880e58fa5e8af9d }}2. base64加密测试/** * base64加密 */public class Bast64Tester {public static void main(String[] args) { String string = \"我是一个字符串\"; String encodeData = Base64Util.encodeData(string); //加密 String decodeData = Base64Util.decodeData(encodeData); // System.out.println(encodeData);//5oiR5piv5LiA5Liq5a2X56ym5Liy System.out.println(decodeData);//我是一个字符串 }}3. SHA加密测试/** * SHA加密 */public class ShaTest {public static void main(String[] args) { String string = \"我是一句话\"; String sha256Crypt = Sha2Crypt.sha256Crypt(string.getBytes()); System.out.println(sha256Crypt);//$5$AFoQTeyt$TiqmobvcQXjXaAQMYosAAO4KI8LfigZMGHzq.Dlp4NC }}4. BCrypt加密测试/** * BCrypt加密 */public class BCryptTest {public static void main(String[] args
- 随机文章
- 核心危机(核心危机魔石合成攻略)
- 饿了么红包怎么用(饿了么红包怎么用微信支付)
- 儿童教育文章(儿童教育)
- 光遇花手先祖位置(安卓光遇手花先祖)
- 广州4a广告公司(广州4a广告公司创意总监年薪)
- 抖音卡(抖音卡顿怎么解决)
- xboxones(xboxone手柄怎么配对主机)
- 陈武简历
- 帆船比赛(帆船比赛视频)
- 海猫鸣泣之时游戏(海猫鸣泣之时游戏在哪玩)
- 韩国媳妇和小雪(韩国媳妇和小雪的父亲工资是多少)
- 儋州市第二中学(儋州市第二中学录取分数线)
- 鬼泣5攻略(鬼泣5攻略第三关怎么跳)
- 地球日主题(2020年世界地球日主题)
- 和柳亚子(和柳亚子先生于田)
- 冰客(冰客果汁)
- yy魔兽(yy魔兽世界)
- 国外成人游戏(国外成人游戏注册需要visa信用卡)
- 充值卡代理(充值卡代理加盟)
- 拆奶罩
- 郭妮小说(恶魔的法则郭妮小说)
- 东天目山(东天目山景区)
- 杭同(杭同培训中心怎么样)
- 蝙蝠给人类的一封信(蝙蝠给人类的一封信)
- 服饰加盟(服饰加盟店招商)
- 疯狂填字(疯狂填字5)
- 点对点短信息(点对点短信息费是什么意思)
- 观音普门品(观音普门品念诵全文)
- 河北省大运会(河北省大运会时间)
- 哈利波特官网(哈利波特官网在哪里)
