oxygenxml.oxygen_18.1 生成KEY代码

  1. import java.io.BufferedReader;  
  2. import java.io.IOException;  
  3. import java.io.InputStreamReader;  
  4. import java.io.PrintStream;  
  5. import java.security.KeyFactory;  
  6. import java.security.NoSuchAlgorithmException;  
  7. import java.security.PrivateKey;  
  8. import java.security.Signature;  
  9. import java.security.spec.InvalidKeySpecException;  
  10. import java.security.spec.PKCS8EncodedKeySpec;  
  11. import java.text.SimpleDateFormat;  
  12. import java.util.Date;  
  13. import java.util.Locale;  
  14. import org.apache.commons.codec.binary.Base64;  
  15.   
  16. public class Keygen {  
  17.     private static SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy", Locale.US);  
  18.   
  19.     private static final byte[] privateKeyData = { 48, -126, 1, 76, 2, 1, 0, 48, -126, 1, 44, 6, 7, 42, -122, 72, -50, 56, 4, 1, 48, -126, 1, 31, 2,  
  20.             -127, -127, 0, -3, 127, 83, -127, 29, 117, 18, 41, 82, -33, 74, -100, 46, -20, -28, -25, -10, 17, -73, 82, 60, -17, 68, 0, -61, 30, 63,  
  21.             -128, -74, 81, 38, 105, 69, 93, 64, 34, 81, -5, 89, 61, -115, 88, -6, -65, -59, -11, -70, 48, -10, -53, -101, 85, 108, -41, -127, 59,  
  22.             -128, 29, 52, 111, -14, 102, 96, -73, 107, -103, 80, -91, -92, -97, -97, -24, 4, 123, 16, 34, -62, 79, -69, -87, -41, -2, -73, -58, 27,  
  23.             -8, 59, 87, -25, -58, -88, -90, 21, 15, 4, -5, -125, -10, -45, -59, 30, -61, 2, 53, 84, 19, 90, 22, -111, 50, -10, 117, -13, -82, 43, 97,  
  24.             -41, 42, -17, -14, 34, 3, 25, -99, -47, 72, 1, -57, 2, 21, 0, -105, 96, 80, -113, 21, 35, 11, -52, -78, -110, -71, -126, -94, -21, -124,  
  25.             11, -16, 88, 28, -11, 2, -127, -127, 0, -9, -31, -96, -123, -42, -101, 61, -34, -53, -68, -85, 92, 54, -72, 87, -71, 121, -108, -81, -69,  
  26.             -6, 58, -22, -126, -7, 87, 76, 11, 61, 7, -126, 103, 81, 89, 87, -114, -70, -44, 89, 79, -26, 113, 7, 16, -127, -128, -76, 73, 22, 113,  
  27.             35, -24, 76, 40, 22, 19, -73, -49, 9, 50, -116, -56, -90, -31, 60, 22, 122, -117, 84, 124, -115, 40, -32, -93, -82, 30, 43, -77, -90,  
  28.             117, -111, 110, -93, 127, 11, -6, 33, 53, 98, -15, -5, 98, 122, 1, 36, 59, -52, -92, -15, -66, -88, 81, -112, -119, -88, -125, -33, -31,  
  29.             90, -27, -97, 6, -110, -117, 102, 94, -128, 123, 85, 37, 100, 1, 76, 59, -2, -49, 73, 42, 4, 23, 2, 21, 0, -106, -49, 66, -124, -79, -94,  
  30.             -48, -108, 26, -46, -57, -110, -117, 14, -38, 1, -77, -127, 0, 14 };  
  31.     private String registrationName;  
  32.     private String company;  
  33.   
  34.     private static PrivateKey getPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException {  
  35.         PKCS8EncodedKeySpec pKCS8EncodedKeySpec = new PKCS8EncodedKeySpec(privateKeyData);  
  36.         return KeyFactory.getInstance("DSA").generatePrivate(pKCS8EncodedKeySpec);  
  37.     }  
  38.   
  39.     private static String convertString(String _string) {  
  40.         StringBuffer stringBuffer = new StringBuffer(_string);  
  41.         int length = stringBuffer.length();  
  42.         for (int i = 0; i < length; ++i) {  
  43.             if ("BADCEFGHIJKLNMOPQRSTUVWXZY0123456789 _-.@".indexOf(Character.toUpperCase(stringBuffer.charAt(i))) != -1)  
  44.                 continue;  
  45.             stringBuffer.setCharAt(i, '_');  
  46.         }  
  47.         return stringBuffer.toString();  
  48.     }  
  49.   
  50.     private static String inputString(BufferedReader _bufferedReader, String _message) throws IOException {  
  51.         String inputLine = null;  
  52.         do {  
  53.             System.out.print(_message);  
  54.             System.out.flush();  
  55.             inputLine = _bufferedReader.readLine();  
  56.         } while ((inputLine == null) || (inputLine.trim().length() == 0));  
  57.         return inputLine;  
  58.     }  
  59.   
  60.     public Keygen(String _registrationName, String _company) {  
  61.         this.registrationName = null;  
  62.         this.company = null;  
  63.         this.registrationName = _registrationName;  
  64.         this.company = _company;  
  65.     }  
  66.   
  67.     private String getLicenseString() throws Exception {  
  68.         StringBuffer buffer = new StringBuffer();  
  69.         buffer.append(convertString(this.registrationName));  
  70.         buffer.append(convertString(this.company));  
  71.         buffer.append(formatter.format(new Date()));  
  72.         buffer.append("0");  
  73.         buffer.append("1000");  
  74.         buffer.append(convertString("Enterprise"));  
  75.         buffer.append(convertString("[Author, Author-Component, XML-Editor, XSLT-Debugger, SVN-Client, Saxon-SA, Diff-Srv, Diff-App, 1]"));  
  76.         buffer.append(convertString("18"));  
  77.         return buffer.toString();  
  78.     }  
  79.   
  80.     private String getLicenseSignature() throws Exception {  
  81.         Signature dsaSignature = Signature.getInstance("SHA1withDSA");  
  82.         dsaSignature.initSign(getPrivateKey());  
  83.         dsaSignature.update(getLicenseString().getBytes());  
  84.   
  85.         return Base64.encodeBase64String(dsaSignature.sign());  
  86.     }  
  87.   
  88.     private String getLicense() throws Exception {  
  89.         StringBuffer buffer = new StringBuffer();  
  90.         buffer.append("Registration_Name=" + this.registrationName).append('\n');  
  91.         buffer.append("Company=" + this.company).append('\n');  
  92.         buffer.append("Date=").append(formatter.format(new Date())).append('\n');  
  93.         buffer.append("Duration=-").append('\n');  
  94.         buffer.append("Number_of_Licenses=1000").append('\n');  
  95.         buffer.append("Category=Enterprise").append('\n');  
  96.         buffer.append("Component=Author,Author-Component,XML-Editor,XSLT-Debugger,SVN-Client,Saxon-SA,Diff-Srv,Diff-App,1").append('\n');  
  97.         buffer.append("Version=18").append('\n');  
  98.         buffer.append("SGN=" + getLicenseSignature());  
  99.         return buffer.toString();  
  100.     }  
  101.   
  102.     public static void main(String[] _args) {  
  103.         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));  
  104.         try {  
  105.             System.out.println("==================================================");  
  106.             System.out.println("=== <oXygen/>XML Editor v17.x license generator ===");  
  107.             System.out.println("==================================================");  
  108.             System.out.println();  
  109.             String registrationName = inputString(bufferedReader, "Registration name : ");  
  110.             String company = inputString(bufferedReader, "Company           : ");  
  111.             System.out.println();  
  112.             System.out.println("==================================================");  
  113.             System.out.println("License: ");  
  114.             System.out.println("==================================================");  
  115.             System.out.println();  
  116.             System.out.println(new Keygen(registrationName, company).getLicense());  
  117.             System.out.println();  
  118.             System.out.println("==================================================");  
  119.         } catch (Exception _exception) {  
  120.             _exception.printStackTrace();  
  121.         } finally {  
  122.             try {  
  123.                 bufferedReader.close();  
  124.             } catch (IOException localIOException1) {  
  125.             }  
  126.         }  
  127.     }  
  128. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值