Search in sources :

Example 1 with Encrypt

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

the class ServiceUtilTest method active.

public static String active(String licenseId, String maccode, String installcode) throws Exception {
    IService srvc = ServiceUtil.getService();
    byte[] serverPublicKey = srvc.getServerPublicKey();
    String s = licenseId + Constants.SEPARATOR + ProtectionFactory.getSeries() + Constants.SEPARATOR + installcode;
    Encrypt en = ProtectionFactory.getEncrypt();
    byte[] k = en.encrypt(serverPublicKey, s.getBytes());
    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;
    } else if (Constants.RETURN_INVALIDBUNDLE.equals(new String(b))) {
        return Constants.RETURN_INVALIDBUNDLE;
    } else if (Constants.RETURN_DBEXCEPTION.equals(new String(b))) {
        return Constants.RETURN_DBEXCEPTION;
    } else if (Constants.RETURN_MUTILTEMPBUNDLE.equals(new String(b))) {
        return Constants.RETURN_MUTILTEMPBUNDLE;
    } else if (Constants.RETURN_EXPIREDLICENSE.equals(new String(b))) {
        return Constants.RETURN_EXPIREDLICENSE;
    } else {
        return "Active Success";
    }
}
Also used : Encrypt(net.heartsome.license.encrypt.Encrypt)

Example 2 with Encrypt

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

the class ServiceUtilTest method check.

public static String check(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.checkLicense(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_CHECKSUCESS.equals(info)) {
        return "Check Success";
    } else if (Constants.RETURN_EXPIREDLICENSE.equals(info)) {
        return "Expired";
    } else {
        return "Invalid";
    }
}
Also used : Encrypt(net.heartsome.license.encrypt.Encrypt)

Example 3 with Encrypt

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

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

the class ServiceUtil method getTempEndDate.

public static String getTempEndDate(String key) throws Exception {
    if (key == null) {
        return null;
    }
    IService srvc = ServiceUtil.getService();
    byte[] serverPublicKey = srvc.getServerPublicKey();
    Encrypt en = ProtectionFactory.getEncrypt();
    String str = srvc.getTempEndDate(StringUtils.toHexString(en.encrypt(serverPublicKey, key.getBytes())), en.getPublicKey());
    byte[] b = StringUtils.toBytes(str);
    b = en.decrypt(en.getPrivateKey(), b);
    key = new String(b);
    if (Constants.RETURN_NULLTEMPENDDATE.equals(key)) {
        return null;
    } else {
        return key;
    }
}
Also used : InstallKeyEncrypt(net.heartsome.license.encrypt.InstallKeyEncrypt) Encrypt(net.heartsome.license.encrypt.Encrypt)

Example 5 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) 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;
        }
    }
}
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)

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