Search in sources :

Example 6 with Encrypt

use of net.heartsome.license.encrypt.Encrypt in project translationstudio8 by heartsome.

the class ServiceUtilTest method cancel.

public static String cancel(String licenseId, String maccode, String installcode) throws Exception {
    IService srvc = ServiceUtil.getService();
    byte[] serverPublicKey = srvc.getServerPublicKey();
    Encrypt en = ProtectionFactory.getEncrypt();
    String info = licenseId + Constants.SEPARATOR + ProtectionFactory.getSeries() + Constants.SEPARATOR + installcode;
    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);
    // }
    return info;
}
Also used : Encrypt(net.heartsome.license.encrypt.Encrypt)

Example 7 with Encrypt

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

Example 8 with Encrypt

use of net.heartsome.license.encrypt.Encrypt 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

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