Search in sources :

Example 1 with LicenseReader

use of net.heartsome.license.LicenseReader 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;
    }
}
Also used : LicenseReader(net.heartsome.license.LicenseReader) KeyGeneratorImpl(net.heartsome.license.generator.KeyGeneratorImpl) IKeyGenerator(net.heartsome.license.generator.IKeyGenerator) MalformedURLException(java.net.MalformedURLException) InstallKeyEncrypt(net.heartsome.license.encrypt.InstallKeyEncrypt) Encrypt(net.heartsome.license.encrypt.Encrypt)

Example 2 with LicenseReader

use of net.heartsome.license.LicenseReader in project translationstudio8 by heartsome.

the class ServiceUtil method cancel.

public static int cancel() throws Exception {
    LicenseReader reader = new LicenseReader(Constants.PRODUCTID);
    String info = reader.getLicenseInfo();
    if (info == null) {
        return Constants.LOGOUT_FAIL;
    }
    IService srvc = ServiceUtil.getService();
    byte[] serverPublicKey = srvc.getServerPublicKey();
    Encrypt en = ProtectionFactory.getEncrypt();
    String str = srvc.logoutLicense(StringUtils.toHexString(en.encrypt(serverPublicKey, info.getBytes())), en.getPublicKey());
    byte[] b = StringUtils.toBytes(str);
    b = en.decrypt(en.getPrivateKey(), b);
    info = new String(b);
    if (Constants.RETURN_LOGOUTSUCESS.equals(info)) {
        return FileUtils.removeFile() ? Constants.LOGOUT_SUCCESS : Constants.LOGOUT_FAIL;
    } else if (Constants.RETURN_INVALIDLICENSE.equals(info)) {
        return FileUtils.removeFile() ? Constants.LOGOUT_SUCCESS : Constants.LOGOUT_FAIL;
    } else {
        return Constants.LOGOUT_FAIL;
    }
}
Also used : LicenseReader(net.heartsome.license.LicenseReader) InstallKeyEncrypt(net.heartsome.license.encrypt.InstallKeyEncrypt) Encrypt(net.heartsome.license.encrypt.Encrypt)

Aggregations

LicenseReader (net.heartsome.license.LicenseReader)2 Encrypt (net.heartsome.license.encrypt.Encrypt)2 InstallKeyEncrypt (net.heartsome.license.encrypt.InstallKeyEncrypt)2 MalformedURLException (java.net.MalformedURLException)1 IKeyGenerator (net.heartsome.license.generator.IKeyGenerator)1 KeyGeneratorImpl (net.heartsome.license.generator.KeyGeneratorImpl)1