fork download
  1. // BroadVision QuickSilver license key foo
  2.  
  3. import java.io.PrintWriter;
  4. import java.text.DateFormat;
  5. import java.util.Date;
  6. import java.util.Locale;
  7.  
  8. class Constant {
  9. static final byte[] encodingTable = new byte[] {
  10. 65, 66, 67, 68, 69, 70, 71, 72, 74, 75,
  11. 76, 77, 78, 80, 81, 82, 83, 84, 85, 86,
  12. 87, 88, 89, 90, 50, 51, 52, 53, 54, 55,
  13. 56, 57 };
  14.  
  15. static final byte[] decodingTable = new byte[128];
  16.  
  17. static int ERR_PARSING_ERROR = -101;
  18.  
  19. static int ERR_WRONG_ROOT_NODE = -102;
  20.  
  21. static int ERR_NO_DOCUMENT_ELEMENT = -103;
  22.  
  23. static int ERR_WRONG_SIGNATURE = -104;
  24.  
  25. static int[] SmallPrimes = new int[] {
  26. 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
  27. 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 };
  28.  
  29. static int[] MedPrimes = new int[] { 977, 983, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039 };
  30.  
  31. static int KEY_CHECKSUM_DIGITS = 1000;
  32.  
  33. static {
  34. byte b;
  35. for (b = 0; b < 127; b++)
  36. decodingTable[b] = -1;
  37. for (b = 65; b <= 72; b++)
  38. decodingTable[b] = (byte)(b - 65);
  39. for (b = 74; b <= 78; b++)
  40. decodingTable[b] = (byte)(b - 74 + 8);
  41. for (b = 80; b <= 90; b++)
  42. decodingTable[b] = (byte)(b - 80 + 13);
  43. for (b = 50; b <= 57; b++)
  44. decodingTable[b] = (byte)(b - 50 + 24);
  45. }
  46. }
  47.  
  48.  
  49.  
  50. class LicUtil {
  51. public static String[] PRODUCTS = new String[] { "Process", "Enterprise" };
  52.  
  53. public static String[][] BVCOMPONENTS = new String[][] { { "Server", "Designer", "Developer", "ContentService" }, { "USSAdapter", "LuceneAdaptor" } };
  54.  
  55. public static String[] COMPONENTS = BVCOMPONENTS[0];
  56.  
  57. public static String[] ENTCOMPONENTS = BVCOMPONENTS[1];
  58.  
  59. public static String[] TYPES = new String[] { "Normal", "Site" };
  60.  
  61. public static String[] OS = new String[] { "SunOS", "HP-UX", "AIX", "Windows", "Linux" };
  62.  
  63. public static int[] OS_INT = new int[] { 1, 2, 4, 8, 16, 255 };
  64.  
  65. public static String[] KONAMODULES = new String[] { "Workbench", "Runtime_Basic" };
  66.  
  67. public static int SUNOS = 1;
  68.  
  69. public static int HPUX = 2;
  70.  
  71. public static int IBMAIX = 4;
  72.  
  73. public static int WIN = 8;
  74.  
  75. public static int LINUX = 16;
  76.  
  77. public static int ALLOS = 255;
  78.  
  79. public static final int VALIDKEY_INSTALLED = 0;
  80.  
  81. public static final int VALIDKEY_ACTIVATED = 1;
  82.  
  83. public static final int VALIDKEY_SYSTEM = 2;
  84.  
  85. public static final int LICENSE_NONE = -1;
  86.  
  87. public static final int INVALIDKEY_RAW = -2;
  88.  
  89. public static final int INVALIDKEY_INSTALLED = -3;
  90.  
  91. public static final int INVALIDKEY_ACTIVATED = -4;
  92.  
  93. public static final int LICENSE_EXPIRE = -5;
  94.  
  95. public static final int MISMATCH_TIMESTAMP = -6;
  96.  
  97. public static final int MISMATCH_OS = -7;
  98.  
  99. public static final int MISMATCH_HARDWARE = -8;
  100.  
  101. public static final int CONNECT_FAILED = -9;
  102.  
  103. public static final int CANNOT_ACTIVATED = -10;
  104.  
  105. public static final int ACTIVATION_LIMIT_REACHED = -11;
  106.  
  107. public static final int OPEN_LICFILE_FAILED = -90;
  108.  
  109. public static final int INVALID_PARAMETER = -99;
  110.  
  111. public static final int UNKNOWN_ERROR = -999;
  112.  
  113. static String LICENSE_FILENAME = "license2.xml";
  114.  
  115. public static String IDtoProduct(String paramString) {
  116. return PRODUCTS[0];
  117. }
  118.  
  119. public static String IDtoProduct(String paramString1, String paramString2) {
  120. return IDtoProduct(paramString1);
  121. }
  122.  
  123. public static String IDtoComponent(String paramString1, String paramString2) {
  124. return COMPONENTS[0];
  125. }
  126.  
  127. public static String IDtoType(String paramString) {
  128. return TYPES[0];
  129. }
  130. }
  131.  
  132.  
  133.  
  134.  
  135. class License {
  136.  
  137. static long MILLISSECTODAY = 86400000L;
  138.  
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145. class Key {
  146. static String ACTEXPIRE_DEFAULT = "30";
  147.  
  148. static String ABSEXPIRE_DEFAULT = "255";
  149.  
  150. static String V2_ABSEXPIRE_DEFAULT = "16383";
  151.  
  152. static int V2_INT_ABSEXPIRE_DEFAULT = 16383;
  153.  
  154. static String VERSION_DEFAULT = "1";
  155.  
  156. static String SPECIAL_DEFAULT = "0";
  157.  
  158. String customer = null;
  159.  
  160. String order = null;
  161.  
  162. String product = null;
  163.  
  164. String component = null;
  165.  
  166. String type = null;
  167.  
  168. String actexpire = null;
  169.  
  170. String absexpire = null;
  171.  
  172. String version = null;
  173.  
  174. String special = null;
  175.  
  176. String os = null;
  177.  
  178. String checksum = null;
  179.  
  180. int subversion = 0;
  181.  
  182. int int_version = -1;
  183.  
  184. String dochecksum = null;
  185.  
  186. Key() {}
  187.  
  188. Key(Key paramKey) {
  189. this.checksum = null;
  190. this.dochecksum = null;
  191. this.customer = paramKey.customer;
  192. this.order = paramKey.order;
  193. this.product = paramKey.product;
  194. this.component = paramKey.component;
  195. this.type = paramKey.type;
  196. this.actexpire = paramKey.actexpire;
  197. this.absexpire = paramKey.absexpire;
  198. this.version = paramKey.version;
  199. this.special = paramKey.special;
  200. this.os = paramKey.os;
  201. this.subversion = paramKey.subversion;
  202. this.int_version = paramKey.int_version;
  203. }
  204.  
  205. String getCustomer() {
  206. return this.customer;
  207. }
  208.  
  209. void setCustomer(String paramString) {
  210. this.customer = paramString;
  211. }
  212.  
  213. String getOrder() {
  214. return this.order;
  215. }
  216.  
  217. void setOrder(String paramString) {
  218. this.order = paramString;
  219. }
  220.  
  221. String getProduct() {
  222. return this.product;
  223. }
  224.  
  225. void setProduct(String paramString) {
  226. this.product = paramString;
  227. }
  228.  
  229. String getComponent() {
  230. return this.component;
  231. }
  232.  
  233. void setComponent(String paramString) {
  234. this.component = paramString;
  235. }
  236.  
  237. String getType() {
  238. return this.type;
  239. }
  240.  
  241. void setType(String paramString) {
  242. this.type = paramString;
  243. }
  244.  
  245. int getSubversion() {
  246. return this.subversion;
  247. }
  248.  
  249. void setSubversion(int paramInt) {
  250. this.subversion = paramInt;
  251. }
  252.  
  253. String getActexpire() {
  254. return this.actexpire;
  255. }
  256.  
  257. void setActexpire(String paramString) {
  258. if (paramString == null) {
  259. this.actexpire = ACTEXPIRE_DEFAULT;
  260. } else {
  261. this.actexpire = paramString;
  262. }
  263. }
  264.  
  265. String getAbsexpire() {
  266. return this.absexpire;
  267. }
  268.  
  269. void setAbsexpire(String paramString) {
  270. if (paramString == null) {
  271. this.absexpire = ABSEXPIRE_DEFAULT;
  272. } else {
  273. this.absexpire = paramString;
  274. }
  275. }
  276.  
  277. int getIntVersion() {
  278. return this.int_version;
  279. }
  280.  
  281. String getVersion() {
  282. return this.version;
  283. }
  284.  
  285. void setVersion(String paramString) {
  286. if (paramString == null) {
  287. this.version = VERSION_DEFAULT;
  288. this.int_version = 1;
  289. } else {
  290. this.version = paramString;
  291. try {
  292. this.int_version = Integer.parseInt(this.version);
  293. } catch (Exception exception) {
  294. this.version = null;
  295. this.int_version = -1;
  296. }
  297. }
  298. }
  299.  
  300. String getSpecial() {
  301. return this.special;
  302. }
  303.  
  304. void setSpecial(String paramString) {
  305. if (paramString == null) {
  306. this.special = SPECIAL_DEFAULT;
  307. } else {
  308. this.special = paramString;
  309. }
  310. }
  311.  
  312. String getOS() {
  313. return this.os;
  314. }
  315.  
  316. void setOS(int paramInt) {
  317. this.os = "" + paramInt;
  318. }
  319.  
  320. String getChecksum() {
  321. return this.checksum;
  322. }
  323.  
  324. void setChecksum(String paramString) {
  325. this.checksum = paramString;
  326. }
  327.  
  328. String doChecksum() {
  329. if (this.dochecksum != null)
  330. return this.dochecksum;
  331. String str1 = "Process"; //LicUtil.IDtoProduct(this.product, this.version);
  332. if ("".equals(str1))
  333. return "ERRORCHECKSUM";
  334. if (this.int_version == 1 && "".equals("Designer"))//LicUtil.IDtoComponent(str1, this.component)))
  335. return "ERRORCHECKSUM";
  336. String str2 = this.customer + this.order + this.product + this.component + this.type + this.actexpire + this.absexpire + this.version + this.special + this.os;
  337. if (this.subversion != 0)
  338. str2 = str2 + this.subversion;
  339. this.dochecksum = getHashcode(str2, 1, 1);
  340. return this.dochecksum;
  341. }
  342.  
  343. static String getHashcode(String paramString, int paramInt1, int paramInt2) {
  344. String str = paramString;
  345. byte[] arrayOfByte = null;
  346. try {
  347. arrayOfByte = str.getBytes("UTF-8");
  348. } catch (Exception exception) {
  349. return "255";
  350. }
  351. long[] arrayOfLong = new long[arrayOfByte.length / 2 + 1];
  352. byte b1;
  353. for (b1 = 0; b1 < arrayOfLong.length; b1++)
  354. arrayOfLong[b1] = 0L;
  355. b1 = 0;
  356. for (byte b2 = 0; b2 < arrayOfByte.length; b2++) {
  357. arrayOfLong[b1] = arrayOfLong[b1] << 8L | arrayOfByte[b2];
  358. if ((b2 & 0x1) == 1)
  359. b1++;
  360. }
  361. long l = 0L;
  362. int i = Constant.SmallPrimes.length;
  363. int j = 0;
  364. int k = Constant.MedPrimes.length;
  365. int m = 0;
  366. int n;
  367. for (n = 0; n < arrayOfLong.length; n++) {
  368. int i1 = Constant.SmallPrimes[j] * Constant.MedPrimes[m];
  369. i1 = i1 >> 1 & 0xF;
  370. l ^= arrayOfLong[n] << i1;
  371. j += paramInt1;
  372. if (j >= i)
  373. j = 0;
  374. m += paramInt2;
  375. if (m >= k)
  376. m = 0;
  377. }
  378. if (paramInt1 == 1 && paramInt2 == 1)
  379. l &= 0x1FFFFFL;
  380. n = (int)l;
  381. return "" + n;
  382. }
  383.  
  384. boolean valid() {
  385. return doChecksum().equals(this.checksum);
  386. }
  387.  
  388. int valid_runtime() {
  389. if (!valid())
  390. return LicUtil.INVALIDKEY_RAW;
  391. int i = getRuntimeOS();
  392. int j = Integer.parseInt(this.os);
  393. return ((i & j) != 0) ? 1 : LicUtil.MISMATCH_OS;
  394. }
  395.  
  396. static int getRuntimeOS() {
  397. return OStoID(System.getProperty("os.name"));
  398. }
  399.  
  400. static int OStoID(String paramString) {
  401. for (byte b = 0; b < LicUtil.OS.length; b++) {
  402. if (paramString != null && paramString.length() >= 7)
  403. paramString = paramString.substring(0, 7);
  404. if (LicUtil.OS[b].equals(paramString)) {
  405. int i = 1;
  406. if (b > 0)
  407. i <<= b;
  408. return i;
  409. }
  410. }
  411. return 0;
  412. }
  413.  
  414. void information(PrintWriter paramPrintWriter) {
  415. paramPrintWriter.println();
  416. paramPrintWriter.println();
  417. paramPrintWriter.println("Customer ID = " + getCustomer());
  418. paramPrintWriter.println("Order ID = " + getOrder());
  419. String str1 = LicUtil.IDtoProduct(getProduct(), this.version);
  420. paramPrintWriter.println("Product = " + str1);
  421. if (this.int_version == 1) {
  422. String str = LicUtil.IDtoComponent(str1, getComponent());
  423. if (LicUtil.ENTCOMPONENTS[0].equals(str)) {
  424. str = "BV-To-FAST 3.2 Adaptor";
  425. } else if (LicUtil.ENTCOMPONENTS[1].equals(str)) {
  426. str = "BV-To-Lucene 1.4 Adaptor";
  427. }
  428. paramPrintWriter.println("Component = " + str);
  429. paramPrintWriter.println("License Type = " + LicUtil.IDtoType(getType()));
  430. }
  431. int i = 0;
  432. try {
  433. i = Integer.parseInt(getActexpire());
  434. if (this.int_version == 1 && this.subversion == 0)
  435. i *= 30;
  436. } catch (Exception exception) {}
  437. paramPrintWriter.println("Install Expire = " + i + " Days");
  438. String str2 = getAbsexpire();
  439. String str3 = "";
  440. if (this.int_version == 1) {
  441. if ("255".equals(str2)) {
  442. str3 = "NO EXPIRATION DATE";
  443. } else {
  444. try {
  445. int j = Integer.parseInt(str2);
  446. Date date = DateFormat.getDateInstance(2, Locale.US).parse("Jan 1, 2004");
  447. long l1 = date.getTime();
  448. long l2 = (j * 30) * License.MILLISSECTODAY;
  449. str3 = DateFormat.getDateInstance(2, Locale.US).format(new Date(l1 + l2));
  450. } catch (Exception exception) {
  451. str3 = "";
  452. }
  453. }
  454. } else {
  455. try {
  456. int j = Integer.parseInt(str2);
  457. if (j == V2_INT_ABSEXPIRE_DEFAULT) {
  458. str3 = "NO EXPIRATION DATE";
  459. } else {
  460. Date date = DateFormat.getDateInstance(2, Locale.US).parse("Jan 1, 2004");
  461. long l1 = date.getTime();
  462. long l2 = j * License.MILLISSECTODAY;
  463. str3 = DateFormat.getDateInstance(2, Locale.US).format(new Date(l1 + l2));
  464. }
  465. } catch (Exception exception) {
  466. str3 = "";
  467. }
  468. }
  469. paramPrintWriter.println("Absolute Expire = " + str3);
  470. if (this.int_version == 1 && this.subversion == 1) {
  471. paramPrintWriter.println("License Version = 1.1");
  472. } else {
  473. paramPrintWriter.println("License Version = " + getVersion());
  474. }
  475. String str4 = getSpecial();
  476. String str5 = "Required";
  477. if ("1".equals(str4)) {
  478. str5 = "Automatic";
  479. } else if ("2".equals(str4)) {
  480. str5 = "Prohibited";
  481. }
  482. paramPrintWriter.println("Activation Option = " + str5);
  483. String str6 = "";
  484. try {
  485. int j = Integer.parseInt(getOS());
  486. int k = LicUtil.OS_INT.length - 1;
  487. if ((LicUtil.OS_INT[k] & j) == LicUtil.OS_INT[k]) {
  488. str6 = "ALL";
  489. } else {
  490. for (byte b = 0; b < k; b++) {
  491. if ((LicUtil.OS_INT[b] & j) == LicUtil.OS_INT[b])
  492. if ("".equals(str6)) {
  493. str6 = LicUtil.OS[b];
  494. } else {
  495. str6 = str6 + " + " + LicUtil.OS[b];
  496. }
  497. }
  498. }
  499. } catch (Exception exception) {
  500. str6 = "";
  501. }
  502. paramPrintWriter.println("OS = " + str6);
  503. }
  504.  
  505. String expirationday() {
  506. String str1 = getAbsexpire();
  507. String str2 = "";
  508. if (this.int_version == 1) {
  509. if ("255".equals(str1)) {
  510. str2 = "NO EXPIRATION DATE";
  511. } else {
  512. try {
  513. int i = Integer.parseInt(str1);
  514. Date date = DateFormat.getDateInstance(2, Locale.US).parse("Jan 1, 2004");
  515. long l1 = date.getTime();
  516. long l2 = (i * 30) * License.MILLISSECTODAY;
  517. str2 = DateFormat.getDateInstance(2, Locale.US).format(new Date(l1 + l2));
  518. } catch (Exception exception) {
  519. str2 = "";
  520. }
  521. }
  522. } else {
  523. try {
  524. int i = Integer.parseInt(str1);
  525. if (i == V2_INT_ABSEXPIRE_DEFAULT) {
  526. str2 = "NO EXPIRATION DATE";
  527. } else {
  528. Date date = DateFormat.getDateInstance(2, Locale.US).parse("Jan 1, 2004");
  529. long l1 = date.getTime();
  530. long l2 = i * License.MILLISSECTODAY;
  531. str2 = DateFormat.getDateInstance(2, Locale.US).format(new Date(l1 + l2));
  532. }
  533. } catch (Exception exception) {
  534. str2 = "";
  535. }
  536. }
  537. return str2;
  538. }
  539. }
  540.  
  541. class KeyServer {
  542. static int POWER2_16 = 65536;
  543.  
  544. static int POWER2_8 = 256;
  545.  
  546. static String encodeKey(Key paramKey) {
  547. int[] arrayOfInt = new int[16];
  548. int i = Integer.parseInt(paramKey.getCustomer());
  549. int j = Integer.parseInt(paramKey.getOrder());
  550. int k = Integer.parseInt(paramKey.getProduct());
  551. int m = Integer.parseInt(paramKey.getComponent());
  552. int n = Integer.parseInt(paramKey.getType());
  553. int i1 = Integer.parseInt(paramKey.getActexpire());
  554. int i2 = Integer.parseInt(paramKey.getAbsexpire());
  555. int i3 = Integer.parseInt(paramKey.getVersion());
  556. int i4 = Integer.parseInt(paramKey.getSpecial());
  557. int i5 = Integer.parseInt(paramKey.getOS());
  558. int i6 = Integer.parseInt(paramKey.getChecksum());
  559. arrayOfInt[0] = i3;
  560. arrayOfInt[1] = k / POWER2_8;
  561. arrayOfInt[2] = k - arrayOfInt[1] * POWER2_8;
  562. int i7 = i2 / POWER2_8;
  563. arrayOfInt[5] = i2 - i7 * POWER2_8;
  564. arrayOfInt[3] = i7 << 2 | i4;
  565. if (i3 == 1) {
  566. arrayOfInt[1] = k;
  567. arrayOfInt[2] = m & 0xFF;
  568. arrayOfInt[3] = paramKey.getSubversion() << 6 | n << 4 | i4;
  569. arrayOfInt[5] = i2;
  570. }
  571. arrayOfInt[4] = i1;
  572. arrayOfInt[6] = i / POWER2_16;
  573. i -= arrayOfInt[6] * POWER2_16;
  574. arrayOfInt[7] = i / POWER2_8;
  575. arrayOfInt[8] = i - arrayOfInt[7] * POWER2_8;
  576. arrayOfInt[9] = j / POWER2_16;
  577. j -= arrayOfInt[9] * POWER2_16;
  578. arrayOfInt[10] = j / POWER2_8;
  579. arrayOfInt[11] = j - arrayOfInt[10] * POWER2_8;
  580. arrayOfInt[12] = i5;
  581. arrayOfInt[13] = i6 & 0xFF;
  582. arrayOfInt[14] = i6 >>> 8 & 0xFF;
  583. arrayOfInt[15] = i6 >>> 16 << 3 & 0xFF;
  584. return convert(arrayOfInt);
  585. }
  586.  
  587. static String convert(int[] paramArrayOfint) {
  588. byte[] arrayOfByte = new byte[25];
  589. for (byte b1 = 0; b1 < 3; b1++) {
  590. int i = paramArrayOfint[b1 * 5 + 0];
  591. int j = paramArrayOfint[b1 * 5 + 1];
  592. int k = paramArrayOfint[b1 * 5 + 2];
  593. int m = paramArrayOfint[b1 * 5 + 3];
  594. int n = paramArrayOfint[b1 * 5 + 4];
  595. arrayOfByte[b1 * 8 + 0] = Constant.encodingTable[i >>> 3 & 0x1F];
  596. arrayOfByte[b1 * 8 + 1] = Constant.encodingTable[(i << 2 | j >>> 6) & 0x1F];
  597. arrayOfByte[b1 * 8 + 2] = Constant.encodingTable[j >>> 1 & 0x1F];
  598. arrayOfByte[b1 * 8 + 3] = Constant.encodingTable[(j << 4 | k >>> 4) & 0x1F];
  599. arrayOfByte[b1 * 8 + 4] = Constant.encodingTable[(k << 1 | m >>> 7) & 0x1F];
  600. arrayOfByte[b1 * 8 + 5] = Constant.encodingTable[m >>> 2 & 0x1F];
  601. arrayOfByte[b1 * 8 + 6] = Constant.encodingTable[(m << 3 | n >>> 5) & 0x1F];
  602. arrayOfByte[b1 * 8 + 7] = Constant.encodingTable[n & 0x1F];
  603. }
  604. arrayOfByte[24] = Constant.encodingTable[paramArrayOfint[15] >>> 3 & 0x1F];
  605. String str = "";
  606. for (byte b2 = 0; b2 < 25; b2++) {
  607. try {
  608. str = new String(arrayOfByte, "UTF-8");
  609. } catch (Exception exception) {
  610. str = "";
  611. }
  612. }
  613. return str;
  614. }
  615. }
  616.  
  617. class Main {
  618. public static void main(String[] paramArrayOfString) throws Exception {
  619. Key k = new Key();
  620. k.setCustomer("42");
  621. k.setOrder("1337");
  622. k.setProduct("0");
  623. k.setComponent("1");
  624. k.setType("0");
  625. k.setActexpire(null); // defaults
  626. k.setAbsexpire(null);
  627. k.setVersion(null);
  628. k.setSpecial(null);
  629. k.setOS(255); // all
  630. k.setChecksum(k.doChecksum());
  631.  
  632. PrintWriter outFile = new PrintWriter(System.out, true);
  633. k.information(outFile);
  634.  
  635. System.out.println(KeyServer.encodeKey(k));
  636. // AEAACAA896AAALSAAW698NBN8
  637. }
  638.  
  639. }
Success #stdin #stdout 0.23s 44404KB
stdin
Standard input is empty
stdout

Customer ID       = 42
Order ID          = 1337
Product           = Process
Component         = Server
License Type      = Normal
Install Expire    = 900 Days
Absolute Expire   = NO EXPIRATION DATE
License Version   = 1
Activation Option = Required
OS                = ALL
AEAACAA896AAALSAAW698NBN8