license文件生成原理
来源:互联网 发布:网络电视剧播放排行榜 编辑:程序博客网 时间:2024/06/10 22:39
- 现在很多J2EE应用都采用一个license文件来授权系统的使用,特别是在系统购买的早期,会提供有限制的license文件对系统进行限制,比如试用版有譬如IP、日期、最大用户数量的限制等。
- 而license控制的方法又有很多,目前比较流行,只要设计的好就很难破解的方法就是采用一对密匙(私匙加密公匙解密)来生成License文件中的Sinature签名内容,再通过Base64或Hex来进行编码。比如原BEA公司现在是Oracle公司的WebLogic就采用的是这种方法来设置License文件。
- 这里只进行一个比较简单的实现:
- 一共三个类:
- A.KeyGenerater类生成公钥私钥对
- B.Signaturer类使用私钥进行签名
- C.SignProvider类用公钥验证
- 公钥和私钥使用Base64加密Base64这个类很多地方都可以查到。
- KeyGenerater类:
- public class KeyGenerater {
- private byte[] priKey;
- private byte[] pubKey;
- public void generater() {
- try {
- KeyPairGenerator keygen = KeyPairGenerator .getInstance("RSA");
- SecureRandom secrand = new SecureRandom();
- secrand.setSeed("www.川江号子.cn".getBytes()); // 初始化随机产生器
- keygen.initialize(1024, secrand);
- KeyPair keys = keygen.genKeyPair();
- PublicKey pubkey = keys.getPublic();
- PrivateKey prikey = keys.getPrivate()
- pubKey = Base64.encodeToByte(pubkey.getEncoded());
- priKey = Base64.encodeToByte(prikey.getEncoded());
- System.out.println("pubKey = " + new String(pubKey));
- System.out.println("priKey = " + new String(priKey));
- } catch (java.lang.Exception e) {
- System.out.println("生成密钥对失败");
- e.printStackTrace();
- }
- }
- public byte[] getPriKey() {
- return priKey;
- }
- public byte[] getPubKey() {
- return pubKey;
- }
- }
- Signaturer 类:
- public class Signaturer {
- public static byte[] sign(byte[] priKeyText, String plainText) {
- try {
- PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(priKeyText));
- KeyFactory keyf = KeyFactory.getInstance("RSA");
- PrivateKey prikey = keyf.generatePrivate(priPKCS8);
- // 用私钥对信息生成数字签名
- Signature signet = java.security.Signature.getInstance("MD5withRSA");
- signet.initSign(prikey);
- signet.update(plainText.getBytes());
- byte[] signed = Base64.encodeToByte(signet.sign());
- return signed;
- } catch (java.lang.Exception e) {
- System.out.println("签名失败");
- e.printStackTrace();
- }
- return null;
- }
- }
- SignProvider 类:
- public class SignProvider {
- private SignProvider() {
- }
- public static boolean verify(byte[] pubKeyText, String plainText,
- byte[] signText) {
- try {
- // 解密由base64编码的公钥,并构造X509EncodedKeySpec对象
- X509EncodedKeySpec bobPubKeySpec = new X509EncodedKeySpec(Base64.decode(pubKeyText));
- // RSA对称加密算法
- KeyFactory keyFactory = KeyFactory.getInstance("RSA");
- // 取公钥匙对象
- PublicKey pubKey = keyFactory.generatePublic(bobPubKeySpec);
- // 解密由base64编码的数字签名
- byte[] signed = Base64.decode(signText);
- Signature signatureChecker = Signature.getInstance("MD5withRSA");
- signatureChecker.initVerify(pubKey);
- signatureChecker.update(plainText.getBytes());
- // 验证签名是否正常
- if (signatureChecker.verify(signed))
- return true;
- else
- return false;
- } catch (Throwable e) {
- System.out.println("校验签名失败");
- e.printStackTrace();
- return false;
- }
- }
- }
- license文件生成原理
- license文件生成原理
- jive license保护原理
- matlab2013a 注册文件license
- PHP生成HTML文件原理
- PHP生成HTML文件原理
- PHP生成HTML文件原理
- 生成license用于验证证书
- win10系统 安装modelsim64位的无法生成license文件的解决办法
- License控制实现原理(20140808)
- 求IDL8.1license文件
- .htaccess和license文件编写
- 项目license证书文件找不到
- smartsvn9破解及license文件
- JSP生成HTML静态文件原理
- 使用Solution Manager生成系统license
- 获取机器的hostid准备生成license
- License
- 配置MySQL主从复制(Replication)服务
- 后pc时代与想法
- Video for Linux
- 常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
- 快速排序的vector简易示例
- license文件生成原理
- linux系统监控(二)--- top详解
- 什么是DOCTYPE 它对网页起何作用?
- 2012第22周移动应用推荐
- Caused by java.lang.ClassNotFoundException javassist.ClassPool
- linux系统监控(三)--- iostat 详解
- Caused by java.lang.NoClassDefFoundError orgapachecommonsfileuploadRequestContext
- mysql delete Error Code : 1064
- Caused by No result type specified for result named 'loginsuc', perhaps the parent package does not