java短连接+MD5加密短链接
短⽹址服务系统系统采⽤了B/S(Browser/Server)模式,传统的浏览器、服务器模式。
在⽣成后的短链接为了不容易被恶意确解,有⾃⼰⼀套独特的加密⽅式,以下简单介绍其加密机制可以能参考:java 短连接+MD5加密短链接
import java.security.MessageDigest;
public class ShotUrlUtil {
public static void main(String[] args) {
System.out.println(shortUrl("www.baidu/"));
}
public static String shortUrl(String url) {
String[] chars = new String[] { "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" ,
"i" , "j" , "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "t" ,
"u" , "v" , "w" , "x" , "y" , "z" , "0" , "1" , "2" , "3" , "4" , "5" ,
"6" , "7" , "8" , "9" , "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" ,
"I" , "J" , "K" , "L" , "M" , "N" , "O" , "P" , "Q" , "R" , "S" , "T" ,
"U" , "V" , "W" , "X" , "Y" , "Z"
};
// 对传⼊⽹址进⾏ MD5 加密
String md5str = getMD5Str(url);
System.out.println(md5str);
String hex = md5str;
String sTempSubString = hex.substring(8, 16);物联网工程专业学什么
long lHexLong = 0x3FFFFFF3 & Long.parseLong (sTempSubString, 16);
String outChars = "" ;
for ( int j = 0; j < 6; j++) {
long index = 0x0000003C & lHexLong;
着字组词outChars += chars[( int ) index];
// 每次循环按位右移 5 位
lHexLong = lHexLong >> 5;
}
return outChars;
}
短⽹址服务平台-缩链,就是快速低成本搭建⾃有短链接及⼆维码系统,⽀持绑定企业⼆级域名和海量域名,可API对接,可设置短链按条件跳转,解决公共域名短链点击率低、部分地区打不开、⼴告劫持等难题,提升转化,强化品牌。
private static String getMD5Str(String str) {
MessageDigest messageDigest = null;
try {描写日月的成语
messageDigest = Instance("MD5");
messageDigest.Bytes("UTF-8"));
} catch (Exception e) {
System.out.println("catch!");
安全生产月总结}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (HexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").HexString(0xFF & byteArray[i]));
不动产证和房产证的区别else
md5StrBuff.HexString(0xFF & byteArray[i]));
}
String();
}
}
>重阳节敬老诗句大全
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论