license文件生成原理

来源:互联网 发布:python代码示例 编辑:程序博客网 时间:2024/06/04 18:29

Open License,开源的许可生成器,实现你自己的许可管理器/应用

2005-07-20 11:57 by 灵感之源, 6122 阅读, 8 评论, 收藏, 编辑
为了给自己的软件产品添加使用限制,如时间长度、使用次数等,往往会使用许可。

许可中包括了使用限制的各种信息,包括:
1、时间长度
2、使用次数
3、版本升级
4、在线注册
5、安装次数

等等。

或许大家会采用自己的实现方式,但市面上流行通用的,比较著名的应该是:XHEO,商业软件,俺不喜欢;)

我最近发现了Open License ,它是SP Extreme公司开发并开源的许可管理器。

它的特点:
1、图形化界面创建许可;
2、支持产品许可;
3、512位加密;
4、许可钥匙;
5、99.9%防破解;
6、各种许可限制;
7、设计/运行的支持;

这里下载Open License。

老实话,这个Open License比较明显地在抄袭XHEO,不过这样更好,尽量把XHEO的功能都弄过来,哈哈。

官方提供了测试例子,我下载并测试了一下,无论我怎么折腾它(强行修改许可文件等),例子照样正确运行,嘿,挺好玩的。


license文件生成原理

标签: byte解密weblogic加密oraclehex
 11372人阅读 评论(1) 收藏 举报
 分类:
 
  1. 现在很多J2EE应用都采用一个license文件来授权系统的使用,特别是在系统购买的早期,会提供有限制的license文件对系统进行限制,比如试用版有譬如IP、日期、最大用户数量的限制等。  
  2.   
  3. license控制的方法又有很多,目前比较流行,只要设计的好就很难破解的方法就是采用一对密匙(私匙加密公匙解密)来生成License文件中的Sinature签名内容,再通过Base64或Hex来进行编码。比如原BEA公司现在是Oracle公司的WebLogic就采用的是这种方法来设置License文件。  
  4.   
  5. 这里只进行一个比较简单的实现:  
  6.   
  7. 一共三个类:  
  8.   
  9. A.KeyGenerater类生成公钥私钥对  
  10.   
  11. B.Signaturer类使用私钥进行签名  
  12.   
  13. C.SignProvider类用公钥验证  
  14.   
  15. 公钥和私钥使用Base64加密Base64这个类很多地方都可以查到。  
  16.   
  17.    
  18.   
  19. KeyGenerater类:  
  20.   
  21.    
  22.   
  23. public class KeyGenerater {   
  24.   
  25.  private byte[] priKey;   
  26.   
  27.  private byte[] pubKey;   
  28.   
  29.  public void generater() {   
  30.   try {   
  31.   
  32.   KeyPairGenerator keygen = KeyPairGenerator .getInstance("RSA");   
  33.   
  34.    SecureRandom secrand = new SecureRandom();   
  35.   
  36.    secrand.setSeed("www.川江号子.cn".getBytes()); // 初始化随机产生器   
  37.   
  38.    keygen.initialize(1024, secrand);   
  39.   
  40.    KeyPair keys = keygen.genKeyPair();   
  41.   
  42.    PublicKey pubkey = keys.getPublic();   
  43.   
  44.    PrivateKey prikey = keys.getPrivate()   
  45.   
  46.    pubKey = Base64.encodeToByte(pubkey.getEncoded());   
  47.   
  48.    priKey = Base64.encodeToByte(prikey.getEncoded());   
  49.   
  50.    System.out.println("pubKey = " + new String(pubKey));   
  51.   
  52.    System.out.println("priKey = " + new String(priKey));   
  53.   
  54.   } catch (java.lang.Exception e) {   
  55.   
  56.    System.out.println("生成密钥对失败");   
  57.   
  58.    e.printStackTrace();   
  59.   
  60.   }   
  61.   
  62.  }   
  63.   
  64.  public byte[] getPriKey() {   
  65.   
  66.   return priKey;   
  67.   
  68.  }   
  69.   
  70.  public byte[] getPubKey() {   
  71.   
  72.   return pubKey;   
  73.   
  74.  }   
  75.   
  76. }  
  77.    
  78.   
  79. Signaturer 类:    
  80.   
  81.    
  82.   
  83. public class Signaturer {   
  84.   
  85.  public static byte[] sign(byte[] priKeyText, String plainText) {   
  86.   
  87.   try {   
  88.   
  89.    PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(priKeyText));   
  90.   
  91.    KeyFactory keyf = KeyFactory.getInstance("RSA");   
  92.   
  93.    PrivateKey prikey = keyf.generatePrivate(priPKCS8);   
  94.   
  95.    // 用私钥对信息生成数字签名   
  96.   
  97.     Signature signet = java.security.Signature.getInstance("MD5withRSA");   
  98.   
  99.    signet.initSign(prikey);   
  100.   
  101.    signet.update(plainText.getBytes());   
  102.   
  103.    byte[] signed = Base64.encodeToByte(signet.sign());   
  104.   
  105.    return signed;   
  106.   
  107.   } catch (java.lang.Exception e) {   
  108.   
  109.    System.out.println("签名失败");   
  110.   
  111.    e.printStackTrace();   
  112.   
  113.   }   
  114.   
  115.   return null;   
  116.   
  117.  }   
  118.   
  119. }   
  120.   
  121.   
  122.  SignProvider 类:  
  123.   
  124. public class SignProvider {   
  125.   
  126.  private SignProvider() {   
  127.   
  128.  }   
  129.   
  130.  public static boolean verify(byte[] pubKeyText, String plainText,   
  131.   
  132.    byte[] signText) {   
  133.   
  134.   try {   
  135.   
  136.    // 解密由base64编码的公钥,并构造X509EncodedKeySpec对象   
  137.   
  138.    X509EncodedKeySpec bobPubKeySpec = new X509EncodedKeySpec(Base64.decode(pubKeyText));   
  139.   
  140.    // RSA对称加密算法   
  141.   
  142.    KeyFactory keyFactory = KeyFactory.getInstance("RSA");   
  143.   
  144.    // 取公钥匙对象   
  145.   
  146.    PublicKey pubKey = keyFactory.generatePublic(bobPubKeySpec);   
  147.   
  148.    // 解密由base64编码的数字签名   
  149.   
  150.    byte[] signed = Base64.decode(signText);   
  151.   
  152.    Signature signatureChecker = Signature.getInstance("MD5withRSA");   
  153.   
  154.    signatureChecker.initVerify(pubKey);   
  155.   
  156.    signatureChecker.update(plainText.getBytes());   
  157.   
  158.    // 验证签名是否正常   
  159.   
  160.    if (signatureChecker.verify(signed))   
  161.   
  162.     return true;   
  163.   
  164.    else   
  165.   
  166.     return false;   
  167.   
  168.   } catch (Throwable e) {   
  169.   
  170.    System.out.println("校验签名失败");   
  171.   
  172.    e.printStackTrace();   
  173.   
  174.    return false;   
  175.   
  176.   }   
  177.   
  178.  }   
  179.   
0
0



0 0
原创粉丝点击