use of net.heartsome.license.generator.IKeyGenerator in project translationstudio8 by heartsome.
the class OfflineActiveDialog method okPressed.
@Override
protected void okPressed() {
LicenseIdValidator va = new LicenseIdValidator(getLicenseId());
if (va.checkLicense()) {
if (va.getType()) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.OfflineActiveDialog.onlyCommercial"));
} else {
if (va.checkEdition()) {
String series = ProtectionFactory.getSeries();
if (series == null || "".equals(series)) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), MessageFormat.format(Messages.getString("license.OfflineActiveDialog.getActiveKeyFail"), StringUtils.getErrorCode(Constants.EXCEPTION_INT5)));
return;
}
String installKey = null;
OffLineActiveService v = new OffLineActiveService();
if (FileUtils.isExsitInstall()) {
int r = v.readInstallFile();
if (r == Constants.EXCEPTION_INT3 || r == Constants.EXCEPTION_INT4) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), MessageFormat.format(Messages.getString("license.OfflineActiveDialog.getActiveKeyFail"), StringUtils.getErrorCode(r)));
return;
} else {
installKey = v.getInstallKey();
}
} else {
int r = v.generateInstallFile();
if (r == Constants.EXCEPTION_INT8) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.OfflineActiveDialog.getActiveKeyByAdmin"));
System.exit(0);
} else if (r == Constants.EXCEPTION_INT10 || r == Constants.EXCEPTION_INT11) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), MessageFormat.format(Messages.getString("license.OfflineActiveDialog.getActiveKeyFail"), StringUtils.getErrorCode(r)));
return;
} else {
installKey = v.getInstallKey();
}
}
IKeyGenerator gen = new KeyGeneratorImpl();
byte[] k = gen.generateKey(getLicenseId(), series, installKey, OffLineEncrypt.publicKey);
Point p = getShell().getLocation();
super.okPressed();
GetActiveKeyDialog dialog = new GetActiveKeyDialog(getShell(), StringUtils.toHexString(k), p);
int result = dialog.open();
if (result != IDialogConstants.OK_ID) {
System.exit(0);
}
} else {
String edition1 = getVersionContent(System.getProperty("TSEdition"));
String editionInput = new LicenseIdGenerator(getLicenseId()).getVersion();
String edition2 = getVersionContent(editionInput);
String message = MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoInvalid1"), edition1, edition2);
ArrayList<HashMap<String, Integer>> list = new ArrayList<HashMap<String, Integer>>();
HashMap<String, Integer> map1 = new HashMap<String, Integer>();
map1.put("start", message.indexOf(edition1));
map1.put("length", edition1.length());
list.add(map1);
HashMap<String, Integer> map2 = new HashMap<String, Integer>();
map2.put("start", message.indexOf(edition2));
map2.put("length", edition2.length());
list.add(map2);
HashMap<String, Integer> map3 = new HashMap<String, Integer>();
map3.put("start", message.lastIndexOf(edition1));
map3.put("length", edition1.length());
list.add(map3);
HashMap<String, Integer> map4 = new HashMap<String, Integer>();
map4.put("start", message.lastIndexOf(edition2));
map4.put("length", edition2.length());
list.add(map4);
new CustomMessageDialog(getShell(), Messages.getString("license.LicenseManageDialog.titleInvalid"), message, list, editionInput).open();
}
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleInvalid"), Messages.getString("license.LicenseManageDialog.infoInvalid"));
}
}
use of net.heartsome.license.generator.IKeyGenerator in project translationstudio8 by heartsome.
the class ServiceUtil method check.
public static int check(String info, byte[] b) throws Exception {
if (info == null) {
LicenseReader reader = new LicenseReader(Constants.PRODUCTID);
info = reader.getLicenseInfo();
}
if (info == null) {
return Constants.STATE_INVALID;
}
String[] arrInfo = getStrFromInfo(info);
String strKeyCode = arrInfo[0];
// String strMacCode = arrInfo[1];
String strInstallCode = arrInfo[2];
if (b == null) {
b = FileUtils.readFile(ProtectionFactory.getFileName(2, Constants.PRODUCTID));
try {
b = InstallKeyEncrypt.decrypt(b);
if (!strInstallCode.equals(new String(b))) {
return Constants.STATE_INVALID;
}
} catch (Exception e) {
e.printStackTrace();
return Constants.STATE_INVALID;
}
}
if (b == null) {
return Constants.STATE_INVALID;
}
IService srvc = ServiceUtil.getService();
byte[] serverPublicKey = srvc.getServerPublicKey();
IKeyGenerator gen = new KeyGeneratorImpl();
byte[] k = gen.generateKey(strKeyCode, strInstallCode, serverPublicKey);
Encrypt en = ProtectionFactory.getEncrypt();
String str = srvc.checkLicense(StringUtils.toHexString(k), en.getPublicKey());
b = StringUtils.toBytes(str);
b = en.decrypt(en.getPrivateKey(), b);
info = new String(b);
if (Constants.RETURN_CHECKSUCESS.equals(info)) {
return Constants.STATE_VALID;
} else if (Constants.RETURN_EXPIREDLICENSE.equals(info)) {
return Constants.STATE_EXPIRED;
} else {
return Constants.STATE_INVALID;
}
}
use of net.heartsome.license.generator.IKeyGenerator in project translationstudio8 by heartsome.
the class ServiceUtil method active.
public static int active(String licenseId) throws Exception {
IService srvc = ServiceUtil.getService();
byte[] serverPublicKey = srvc.getServerPublicKey();
IKeyGenerator gen = new KeyGeneratorImpl();
byte[] k = gen.generateKey(licenseId, serverPublicKey);
Encrypt en = ProtectionFactory.getEncrypt();
String str = srvc.activeLicense(StringUtils.toHexString(k), en.getPublicKey());
byte[] b = StringUtils.toBytes(str);
b = en.decrypt(en.getPrivateKey(), b);
// System.out.println(new String(b));
if (Constants.RETURN_INVALIDLICENSE.equals(new String(b))) {
return Constants.RETURN_INVALIDLICENSE_INT;
} else if (Constants.RETURN_INVALIDBUNDLE.equals(new String(b))) {
return Constants.RETURN_INVALIDBUNDLE_INT;
} else if (Constants.RETURN_DBEXCEPTION.equals(new String(b))) {
return Constants.RETURN_DBEXCEPTION_INT;
} else if (Constants.RETURN_MUTILTEMPBUNDLE.equals(new String(b))) {
return Constants.RETURN_MUTILTEMPBUNDLE_INT;
} else if (Constants.RETURN_EXPIREDLICENSE.equals(new String(b))) {
return Constants.RETURN_EXPIREDLICENSE_INT;
} else {
FileUtils.writeFile(b, ProtectionFactory.getFileName(1, Constants.PRODUCTID));
FileUtils.writeFile(InstallKeyEncrypt.encrypt(gen.getInstallKey().getBytes()), ProtectionFactory.getFileName(2, 89));
if (FileUtils.isExsit()) {
return Constants.ACTIVE_OK_INT;
} else {
return Constants.RETURN_DBEXCEPTION_INT;
}
}
}
use of net.heartsome.license.generator.IKeyGenerator in project translationstudio8 by heartsome.
the class ServiceUtil method active.
public static int active(String licenseId, ProgressBar bar) throws Exception {
boolean result = FileUtils.writeFile(new byte[] { '1', '1' }, ProtectionFactory.getFileName(0, Constants.PRODUCTID));
if (!result) {
return Constants.EXCEPTION_INT8;
} else {
FileUtils.removeFile(ProtectionFactory.getFileName(0, Constants.PRODUCTID));
}
IService srvc = ServiceUtil.getService();
bar.setSelection(1);
String series = ProtectionFactory.getSeries();
if (series == null || "".equals(series)) {
return Constants.EXCEPTION_INT5;
}
byte[] serverPublicKey = srvc.getServerPublicKey();
bar.setSelection(2);
IKeyGenerator gen = new KeyGeneratorImpl();
byte[] k = gen.generateKey(licenseId, series, serverPublicKey);
if (k == null) {
return Constants.EXCEPTION_INT9;
}
bar.setSelection(3);
Encrypt en = ProtectionFactory.getEncrypt();
bar.setSelection(4);
String str = srvc.activeLicense(StringUtils.toHexString(k), en.getPublicKey(), ProtectionFactory.getPlatform());
bar.setSelection(5);
bar.setSelection(6);
byte[] b = StringUtils.toBytes(str);
bar.setSelection(7);
b = en.decrypt(en.getPrivateKey(), b);
if (b == null) {
return Constants.EXCEPTION_INT7;
}
bar.setSelection(8);
String info = new String(b);
if (Constants.RETURN_INVALIDLICENSE.equals(info)) {
return Constants.RETURN_INVALIDLICENSE_INT;
} else if (Constants.RETURN_INVALIDBUNDLE.equals(info)) {
return Constants.RETURN_INVALIDBUNDLE_INT;
} else if (Constants.RETURN_DBEXCEPTION.equals(info)) {
return Constants.EXCEPTION_INT13;
} else if (Constants.RETURN_MUTILTEMPBUNDLE.equals(info)) {
return Constants.RETURN_MUTILTEMPBUNDLE_INT;
} else if (Constants.RETURN_EXPIREDLICENSE.equals(info)) {
return Constants.RETURN_EXPIREDLICENSE_INT;
} else if (Constants.RETURN_STOPLICENSE.equals(info)) {
return Constants.RETURN_STOPLICENSE_INT;
} else {
result = FileUtils.writeFile(b, ProtectionFactory.getFileName(1, Constants.PRODUCTID));
if (!result) {
return Constants.EXCEPTION_INT12;
}
bar.setSelection(9);
b = InstallKeyEncrypt.encrypt(StringUtils.handle(gen.getInstallKey(), 1, 3, 2).getBytes());
if (b == null) {
return Constants.EXCEPTION_INT10;
}
result = FileUtils.writeFile(b, ProtectionFactory.getFileName(2, Constants.PRODUCTID));
if (!result) {
return Constants.EXCEPTION_INT11;
}
bar.setSelection(10);
System.getProperties().setProperty("TSState", "true");
return Constants.ACTIVE_OK_INT;
}
}
use of net.heartsome.license.generator.IKeyGenerator in project translationstudio8 by heartsome.
the class OffLineActiveService method generateInstallFile.
/**
* 生成安装码文件
* @return ;
*/
public int generateInstallFile() {
boolean result = FileUtils.writeFile(new byte[] { '1', '1' }, ProtectionFactory.getFileName(0, Constants.PRODUCTID));
if (!result) {
return Constants.EXCEPTION_INT8;
} else {
FileUtils.removeFile(ProtectionFactory.getFileName(0, Constants.PRODUCTID));
}
IKeyGenerator gen = new KeyGeneratorImpl();
installKey = gen.generateInstallKey();
byte[] t = InstallKeyEncrypt.encrypt(StringUtils.handle(gen.getInstallKey(), 1, 3, 2).getBytes());
if (t == null) {
return Constants.EXCEPTION_INT10;
}
result = FileUtils.writeFile(t, ProtectionFactory.getFileName(2, Constants.PRODUCTID));
if (!result) {
return Constants.EXCEPTION_INT11;
}
return Constants.STATE_VALID;
}
Aggregations