jsp url地址加密问题

如何给jsp的url进行加密... 如何给jsp 的url进行加密 展开
 我来答
千锋教育
2016-01-21 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
展开全部
jsp中url地址加密通常使用对称加密如:DES或者是PBE算法。
加密算法如下:
public static String encrypt(String key, String plainText) throws Exception {
String encryptTxt = "";
try {
byte[] salt = new byte[8];
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(key.getBytes());
byte[] digest = md.digest();
for (int i = 0; i < 8; i++) {
salt[i] = digest[i];
}
PBEKeySpec pbeKeySpec = new PBEKeySpec(key.toCharArray());
SecretKeyFactory keyFactory = SecretKeyFactory
.getInstance("PBEWithMD5AndDES");
SecretKey skey = keyFactory.generateSecret(pbeKeySpec);
PBEParameterSpec paramSpec = new PBEParameterSpec(salt, ITERATIONS);
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(Cipher.ENCRYPT_MODE, skey, paramSpec);
byte[] cipherText = cipher.doFinal(plainText.getBytes());
String saltString = new String(Base64.encode(salt));
String ciphertextString = new String(Base64.encode(cipherText));
return saltString + ciphertextString;
} catch (Exception e) {
throw new Exception("Encrypt Text Error:" + e.getMessage(), e);
}
使用方法:
把jsp?后面的参数作为参数传入encrypt();然后就可以返回加密串了。
Storm代理
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I... 点击进入详情页
本回答由Storm代理提供
疏狂山人
推荐于2016-08-14 · TA获得超过1940个赞
知道小有建树答主
回答量:395
采纳率:100%
帮助的人:217万
展开全部
主要是针对url后面的参数进行加密,然后保存起来
访问的时候根据加密后的信息去查找出实际的参数
给你提供给现在用的比较多的短地址加密的方法:
import java.security.MessageDigest;
/**
* 短地址的生成
* @author sunxy
* 2013-1-9
*/
public class ShortUrlGenerator {
private final static String[] hexDigits = {
"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f"};

public static String byteArrayToHexString(byte[] b){
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++){
resultSb.append(byteToHexString(b[i]));
}
return resultSb.toString();
}

private static String byteToHexString(byte b){
int n = b;
if (n < 0)
n = 256 + n;
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}

public static String MD5Encode(String origin){
String resultString = null;
try {

resultString=new String(origin);
MessageDigest md = MessageDigest.getInstance("MD5");

resultString.trim();

resultString=byteArrayToHexString(md.digest(resultString.getBytes("UTF-8")));
}catch (Exception ex){}
return resultString;
}

public static String[] ShortText(String string){
String key = "SUNXY"; //自定义生成MD5加密字符串前的混合KEY
String[] chars = new String[]{ //要使用生成URL的字符
"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"
};

String hex = MD5Encode(key + string);
int hexLen = hex.length();
int subHexLen = hexLen / 8;
String[] ShortStr = new String[4];
for (int i = 0; i < subHexLen; i++) {
String outChars = "";
int j = i + 1;
String subHex = hex.substring(i * 8, j * 8);
long idx = Long.valueOf("3FFFFFFF", 16) & Long.valueOf(subHex, 16);
for (int k = 0; k < 6; k++) {
int index = (int) (Long.valueOf("0000003D", 16) & idx);
outChars += chars[index];
idx = idx >> 5;
}
ShortStr[i] = outChars;
}

return ShortStr;
}

private static void print(Object messagr){
System.out.println(messagr);
}
public static void main(String[] args) {
String url = "189022881&a=111118:09sz0000123456789987654321";
for (String string : ShortText(url)) {
print(string);
}
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zhoushixc
2013-03-28 · 超过24用户采纳过TA的回答
知道答主
回答量:77
采纳率:0%
帮助的人:68.8万
展开全部
URL重写,或者使用rest和ant风格的传参,其他就不知道了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式