如何在Wicket中加密/编码URL

在Wicket中,对URL进行编码或加密是一项非常简单的任务,默认情况下会提供此功能,您只需激活它即可。

Wicket默认普通URL

http://localhost:8080/WicketExamples/?wicket:interface=:0:urlQueryPanel:

Wicket编码或加密的URL

http://localhost:8080/WicketExamples/?x=YwbAGQPpvT9MHF2-6S6FwvocqYPuA

要启用此功能,请将以下代码粘贴到Wicket的Web应用程序类中。

@Override
	protected IRequestCycleProcessor newRequestCycleProcessor() {

		return new WebRequestCycleProcessor() {
			protected IRequestCodingStrategy newRequestCodingStrategy() {
				return new CryptedUrlWebRequestCodingStrategy(
					new WebRequestCodingStrategy());
			}
		};
	}

查看完整示例...

package com.mkyong;

import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequestCycleProcessor;
import org.apache.wicket.protocol.http.request.CryptedUrlWebRequestCodingStrategy;
import org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
import org.apache.wicket.request.IRequestCodingStrategy;
import org.apache.wicket.request.IRequestCycleProcessor;
import com.mkyong.user.UserPage;

public class WicketApplication extends WebApplication {

	@Override
	public Class<UserPage> getHomePage() {

		return UserPage.class; // return default page
	}

	@Override
	protected IRequestCycleProcessor newRequestCycleProcessor() {

		return new WebRequestCycleProcessor() {
			protected IRequestCodingStrategy newRequestCodingStrategy() {
				return new CryptedUrlWebRequestCodingStrategy(
					new WebRequestCodingStrategy());
			}
		};
	}

}

做完了

有点想

Wicket使用基于密码的加密机制来编码和解码URL。 所有必要的类位于“ wicket-1.4-rc1-sources.jar \ org \ apache \ wicket \ util \ crypt ”。 我认为最强大的功能是单个会话随机加密密钥,它使用会话和UUID生成它,以便每个访问者都使用自己的加密密钥(不同的http会话)。

文件:KeyInSessionSunJceCryptFactory.java

if (key == null)
{
	// generate new key
	key = session.getId() + "." + UUID.randomUUID().toString();
	session.setAttribute(keyAttr, key);
}

在基于密码的加密机制中,“ Salt”和“ Iterator count”是公开的,但是像上面那样具有强大的加密密钥(会话+ UUID),即使您拥有Wicket的URL编码功能,也很难对其进行解码。检票口的源代码在手上。

如果您认为Wicket的默认加密机制不够安全,则可以轻松实现其他加密机制,例如AESSHA

注意
Wicket使用SunJceCrypt类作为默认URL编码和解码实现。

参考文献

  1. Wicket URL编码策略
  2. 小门混淆网址

翻译自: https://mkyong.com/wicket/how-do-encrypt-encode-url-in-wicket/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值