// BroadVision QuickSilver license key foo
import java.io.PrintWriter;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
class Constant {
static final byte[] encodingTable = new byte[] {
65, 66, 67, 68, 69, 70, 71, 72, 74, 75,
76, 77, 78, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 50, 51, 52, 53, 54, 55,
56, 57 };
static final byte[] decodingTable = new byte[128];
static int ERR_PARSING_ERROR = -101;
static int ERR_WRONG_ROOT_NODE = -102;
static int ERR_NO_DOCUMENT_ELEMENT = -103;
static int ERR_WRONG_SIGNATURE = -104;
static int[] SmallPrimes = new int[] {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71 };
static int[] MedPrimes = new int[] { 977, 983, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039 };
static int KEY_CHECKSUM_DIGITS = 1000;
static {
byte b;
for (b = 0; b < 127; b++)
decodingTable[b] = -1;
for (b = 65; b <= 72; b++)
decodingTable[b] = (byte)(b - 65);
for (b = 74; b <= 78; b++)
decodingTable[b] = (byte)(b - 74 + 8);
for (b = 80; b <= 90; b++)
decodingTable[b] = (byte)(b - 80 + 13);
for (b = 50; b <= 57; b++)
decodingTable[b] = (byte)(b - 50 + 24);
}
}
class LicUtil {
public static String[] PRODUCTS
= new String[] { "Process",
"Enterprise" };
public static String[][] BVCOMPONENTS
= new String[][] { { "Server",
"Designer",
"Developer",
"ContentService" },
{ "USSAdapter",
"LuceneAdaptor" } };
public static String[] COMPONENTS
= BVCOMPONENTS
[0];
public static String[] ENTCOMPONENTS
= BVCOMPONENTS
[1];
public static String[] TYPES
= new String[] { "Normal",
"Site" };
public static String[] OS
= new String[] { "SunOS",
"HP-UX",
"AIX",
"Windows",
"Linux" };
public static int[] OS_INT = new int[] { 1, 2, 4, 8, 16, 255 };
public static String[] KONAMODULES
= new String[] { "Workbench",
"Runtime_Basic" };
public static int SUNOS = 1;
public static int HPUX = 2;
public static int IBMAIX = 4;
public static int WIN = 8;
public static int LINUX = 16;
public static int ALLOS = 255;
public static final int VALIDKEY_INSTALLED = 0;
public static final int VALIDKEY_ACTIVATED = 1;
public static final int VALIDKEY_SYSTEM = 2;
public static final int LICENSE_NONE = -1;
public static final int INVALIDKEY_RAW = -2;
public static final int INVALIDKEY_INSTALLED = -3;
public static final int INVALIDKEY_ACTIVATED = -4;
public static final int LICENSE_EXPIRE = -5;
public static final int MISMATCH_TIMESTAMP = -6;
public static final int MISMATCH_OS = -7;
public static final int MISMATCH_HARDWARE = -8;
public static final int CONNECT_FAILED = -9;
public static final int CANNOT_ACTIVATED = -10;
public static final int ACTIVATION_LIMIT_REACHED = -11;
public static final int OPEN_LICFILE_FAILED = -90;
public static final int INVALID_PARAMETER = -99;
public static final int UNKNOWN_ERROR = -999;
static String LICENSE_FILENAME
= "license2.xml";
return PRODUCTS[0];
}
return IDtoProduct(paramString1);
}
return COMPONENTS[0];
}
return TYPES[0];
}
}
class License {
static long MILLISSECTODAY = 86400000L;
}
static String ACTEXPIRE_DEFAULT
= "30";
static String ABSEXPIRE_DEFAULT
= "255";
static String V2_ABSEXPIRE_DEFAULT
= "16383";
static int V2_INT_ABSEXPIRE_DEFAULT = 16383;
static String VERSION_DEFAULT
= "1";
static String SPECIAL_DEFAULT
= "0";
int subversion = 0;
int int_version = -1;
this.checksum = null;
this.dochecksum = null;
this.customer = paramKey.customer;
this.order = paramKey.order;
this.product = paramKey.product;
this.component = paramKey.component;
this.type = paramKey.type;
this.actexpire = paramKey.actexpire;
this.absexpire = paramKey.absexpire;
this.version = paramKey.version;
this.special = paramKey.special;
this.os = paramKey.os;
this.subversion = paramKey.subversion;
this.int_version = paramKey.int_version;
}
return this.customer;
}
void setCustomer
(String paramString
) { this.customer = paramString;
}
return this.order;
}
void setOrder
(String paramString
) { this.order = paramString;
}
return this.product;
}
void setProduct
(String paramString
) { this.product = paramString;
}
return this.component;
}
void setComponent
(String paramString
) { this.component = paramString;
}
return this.type;
}
void setType
(String paramString
) { this.type = paramString;
}
int getSubversion() {
return this.subversion;
}
void setSubversion(int paramInt) {
this.subversion = paramInt;
}
return this.actexpire;
}
void setActexpire
(String paramString
) { if (paramString == null) {
this.actexpire = ACTEXPIRE_DEFAULT;
} else {
this.actexpire = paramString;
}
}
return this.absexpire;
}
void setAbsexpire
(String paramString
) { if (paramString == null) {
this.absexpire = ABSEXPIRE_DEFAULT;
} else {
this.absexpire = paramString;
}
}
int getIntVersion() {
return this.int_version;
}
return this.version;
}
void setVersion
(String paramString
) { if (paramString == null) {
this.version = VERSION_DEFAULT;
this.int_version = 1;
} else {
this.version = paramString;
try {
this.
int_version = Integer.
parseInt(this.
version); this.version = null;
this.int_version = -1;
}
}
}
return this.special;
}
void setSpecial
(String paramString
) { if (paramString == null) {
this.special = SPECIAL_DEFAULT;
} else {
this.special = paramString;
}
}
return this.os;
}
void setOS(int paramInt) {
this.os = "" + paramInt;
}
return this.checksum;
}
void setChecksum
(String paramString
) { this.checksum = paramString;
}
if (this.dochecksum != null)
return this.dochecksum;
String str1
= "Process"; //LicUtil.IDtoProduct(this.product, this.version); if ("".equals(str1))
return "ERRORCHECKSUM";
if (this.int_version == 1 && "".equals("Designer"))//LicUtil.IDtoComponent(str1, this.component)))
return "ERRORCHECKSUM";
String str2
= this.
customer + this.
order + this.
product + this.
component + this.
type + this.
actexpire + this.
absexpire + this.
version + this.
special + this.
os; if (this.subversion != 0)
str2 = str2 + this.subversion;
this.dochecksum = getHashcode(str2, 1, 1);
return this.dochecksum;
}
static String getHashcode
(String paramString,
int paramInt1,
int paramInt2
) { byte[] arrayOfByte = null;
try {
arrayOfByte = str.getBytes("UTF-8");
return "255";
}
long[] arrayOfLong = new long[arrayOfByte.length / 2 + 1];
byte b1;
for (b1 = 0; b1 < arrayOfLong.length; b1++)
arrayOfLong[b1] = 0L;
b1 = 0;
for (byte b2 = 0; b2 < arrayOfByte.length; b2++) {
arrayOfLong[b1] = arrayOfLong[b1] << 8L | arrayOfByte[b2];
if ((b2 & 0x1) == 1)
b1++;
}
long l = 0L;
int i = Constant.SmallPrimes.length;
int j = 0;
int k = Constant.MedPrimes.length;
int m = 0;
int n;
for (n = 0; n < arrayOfLong.length; n++) {
int i1 = Constant.SmallPrimes[j] * Constant.MedPrimes[m];
i1 = i1 >> 1 & 0xF;
l ^= arrayOfLong[n] << i1;
j += paramInt1;
if (j >= i)
j = 0;
m += paramInt2;
if (m >= k)
m = 0;
}
if (paramInt1 == 1 && paramInt2 == 1)
l &= 0x1FFFFFL;
n = (int)l;
return "" + n;
}
boolean valid() {
return doChecksum().equals(this.checksum);
}
int valid_runtime() {
if (!valid())
return LicUtil.INVALIDKEY_RAW;
int i = getRuntimeOS();
return ((i & j) != 0) ? 1 : LicUtil.MISMATCH_OS;
}
static int getRuntimeOS() {
return OStoID
(System.
getProperty("os.name")); }
static int OStoID
(String paramString
) { for (byte b = 0; b < LicUtil.OS.length; b++) {
if (paramString != null && paramString.length() >= 7)
paramString = paramString.substring(0, 7);
if (LicUtil.OS[b].equals(paramString)) {
int i = 1;
if (b > 0)
i <<= b;
return i;
}
}
return 0;
}
paramPrintWriter.println();
paramPrintWriter.println();
paramPrintWriter.println("Customer ID = " + getCustomer());
paramPrintWriter.println("Order ID = " + getOrder());
String str1
= LicUtil.
IDtoProduct(getProduct
(),
this.
version); paramPrintWriter.println("Product = " + str1);
if (this.int_version == 1) {
String str
= LicUtil.
IDtoComponent(str1, getComponent
()); if (LicUtil.ENTCOMPONENTS[0].equals(str)) {
str = "BV-To-FAST 3.2 Adaptor";
} else if (LicUtil.ENTCOMPONENTS[1].equals(str)) {
str = "BV-To-Lucene 1.4 Adaptor";
}
paramPrintWriter.println("Component = " + str);
paramPrintWriter.println("License Type = " + LicUtil.IDtoType(getType()));
}
int i = 0;
try {
i
= Integer.
parseInt(getActexpire
()); if (this.int_version == 1 && this.subversion == 0)
i *= 30;
paramPrintWriter.println("Install Expire = " + i + " Days");
if (this.int_version == 1) {
if ("255".equals(str2)) {
str3 = "NO EXPIRATION DATE";
} else {
try {
long l1 = date.getTime();
long l2 = (j * 30) * License.MILLISSECTODAY;
str3 = "";
}
}
} else {
try {
if (j == V2_INT_ABSEXPIRE_DEFAULT) {
str3 = "NO EXPIRATION DATE";
} else {
long l1 = date.getTime();
long l2 = j * License.MILLISSECTODAY;
}
str3 = "";
}
}
paramPrintWriter.println("Absolute Expire = " + str3);
if (this.int_version == 1 && this.subversion == 1) {
paramPrintWriter.println("License Version = 1.1");
} else {
paramPrintWriter.println("License Version = " + getVersion());
}
if ("1".equals(str4)) {
str5 = "Automatic";
} else if ("2".equals(str4)) {
str5 = "Prohibited";
}
paramPrintWriter.println("Activation Option = " + str5);
try {
int k = LicUtil.OS_INT.length - 1;
if ((LicUtil.OS_INT[k] & j) == LicUtil.OS_INT[k]) {
str6 = "ALL";
} else {
for (byte b = 0; b < k; b++) {
if ((LicUtil.OS_INT[b] & j) == LicUtil.OS_INT[b])
if ("".equals(str6)) {
str6 = LicUtil.OS[b];
} else {
str6 = str6 + " + " + LicUtil.OS[b];
}
}
}
str6 = "";
}
paramPrintWriter.println("OS = " + str6);
}
if (this.int_version == 1) {
if ("255".equals(str1)) {
str2 = "NO EXPIRATION DATE";
} else {
try {
long l1 = date.getTime();
long l2 = (i * 30) * License.MILLISSECTODAY;
str2 = "";
}
}
} else {
try {
if (i == V2_INT_ABSEXPIRE_DEFAULT) {
str2 = "NO EXPIRATION DATE";
} else {
long l1 = date.getTime();
long l2 = i * License.MILLISSECTODAY;
}
str2 = "";
}
}
return str2;
}
}
class KeyServer {
static int POWER2_16 = 65536;
static int POWER2_8 = 256;
int[] arrayOfInt = new int[16];
int i
= Integer.
parseInt(paramKey.
getCustomer()); int j
= Integer.
parseInt(paramKey.
getOrder()); int k
= Integer.
parseInt(paramKey.
getProduct()); int m
= Integer.
parseInt(paramKey.
getComponent()); int n
= Integer.
parseInt(paramKey.
getType()); int i1
= Integer.
parseInt(paramKey.
getActexpire()); int i2
= Integer.
parseInt(paramKey.
getAbsexpire()); int i3
= Integer.
parseInt(paramKey.
getVersion()); int i4
= Integer.
parseInt(paramKey.
getSpecial()); int i5
= Integer.
parseInt(paramKey.
getOS()); int i6
= Integer.
parseInt(paramKey.
getChecksum()); arrayOfInt[0] = i3;
arrayOfInt[1] = k / POWER2_8;
arrayOfInt[2] = k - arrayOfInt[1] * POWER2_8;
int i7 = i2 / POWER2_8;
arrayOfInt[5] = i2 - i7 * POWER2_8;
arrayOfInt[3] = i7 << 2 | i4;
if (i3 == 1) {
arrayOfInt[1] = k;
arrayOfInt[2] = m & 0xFF;
arrayOfInt[3] = paramKey.getSubversion() << 6 | n << 4 | i4;
arrayOfInt[5] = i2;
}
arrayOfInt[4] = i1;
arrayOfInt[6] = i / POWER2_16;
i -= arrayOfInt[6] * POWER2_16;
arrayOfInt[7] = i / POWER2_8;
arrayOfInt[8] = i - arrayOfInt[7] * POWER2_8;
arrayOfInt[9] = j / POWER2_16;
j -= arrayOfInt[9] * POWER2_16;
arrayOfInt[10] = j / POWER2_8;
arrayOfInt[11] = j - arrayOfInt[10] * POWER2_8;
arrayOfInt[12] = i5;
arrayOfInt[13] = i6 & 0xFF;
arrayOfInt[14] = i6 >>> 8 & 0xFF;
arrayOfInt[15] = i6 >>> 16 << 3 & 0xFF;
return convert(arrayOfInt);
}
static String convert
(int[] paramArrayOfint
) { byte[] arrayOfByte = new byte[25];
for (byte b1 = 0; b1 < 3; b1++) {
int i = paramArrayOfint[b1 * 5 + 0];
int j = paramArrayOfint[b1 * 5 + 1];
int k = paramArrayOfint[b1 * 5 + 2];
int m = paramArrayOfint[b1 * 5 + 3];
int n = paramArrayOfint[b1 * 5 + 4];
arrayOfByte[b1 * 8 + 0] = Constant.encodingTable[i >>> 3 & 0x1F];
arrayOfByte[b1 * 8 + 1] = Constant.encodingTable[(i << 2 | j >>> 6) & 0x1F];
arrayOfByte[b1 * 8 + 2] = Constant.encodingTable[j >>> 1 & 0x1F];
arrayOfByte[b1 * 8 + 3] = Constant.encodingTable[(j << 4 | k >>> 4) & 0x1F];
arrayOfByte[b1 * 8 + 4] = Constant.encodingTable[(k << 1 | m >>> 7) & 0x1F];
arrayOfByte[b1 * 8 + 5] = Constant.encodingTable[m >>> 2 & 0x1F];
arrayOfByte[b1 * 8 + 6] = Constant.encodingTable[(m << 3 | n >>> 5) & 0x1F];
arrayOfByte[b1 * 8 + 7] = Constant.encodingTable[n & 0x1F];
}
arrayOfByte[24] = Constant.encodingTable[paramArrayOfint[15] >>> 3 & 0x1F];
for (byte b2 = 0; b2 < 25; b2++) {
try {
str
= new String(arrayOfByte,
"UTF-8"); str = "";
}
}
return str;
}
}
class Main {
k.setCustomer("42");
k.setOrder("1337");
k.setProduct("0");
k.setComponent("1");
k.setType("0");
k.setActexpire(null); // defaults
k.setAbsexpire(null);
k.setVersion(null);
k.setSpecial(null);
k.setOS(255); // all
k.setChecksum(k.doChecksum());
k.information(outFile);
System.
out.
println(KeyServer.
encodeKey(k
)); // AEAACAA896AAALSAAW698NBN8
}
}