Generating serial or hex code for product licensing

依然范特西╮ 提交于 2019-12-11 19:35:36

问题


Is there way to generate serial/hex code something like: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx using java api? when product decipher the code it should able to extract

  1. Name
  2. Validity
  3. Mac Address
  4. Additional information

Code will be generated based on above factors. I have tried to RSA/ECB/PKCS1Padding with private key/public key. and then converting to HEX, but it needs private key sixe of 4096 and hex code generated is too long!

public class ProductKeyGenerator {
private static final String transformation = "RSA/ECB/PKCS1Padding";

public static void main(String[] args) {
    String cleartext = "CN=CompanyName;mac=some mac;@host=somehost;email=admin@somedomain.com;issued=01/01/20013;expire=12/12/2013";
    ProductKeyGenerator pgen = new ProductKeyGenerator();
    String productKey = pgen.generate(cleartext);
    System.out.println(productKey);
}

   ...
   ...
   ...
String generate(String data) {
    //encrypted hex
    String hexEnc = null;
    try {
        //--sign
        String signature = sign(data);
        data += ";sign=" + signature;

        byte[] dataBytes = data.getBytes("utf-8");
        //encrypt
        byte[] encBytes = encrypt(dataBytes);
        hexEnc = Hex.encodeHexString(encBytes);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hexEnc;
}

String sign(String text) {
    String signed = null;
    try {
        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        byte[] data = text.getBytes("utf-8");
        byte[] digitalSignature = signData(data);
        signed = Hex.encodeHexString(digitalSignature);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return signed;
}
   ...
   ...
   ...

   }

回答1:


With custom data you can't create a serial number with fixed length. But you can associate a serial number with information e.g. in database. Simple serial number generator:

String serial = UUID.randomUUID().toString().toUpperCase();
System.out.println(serial);

PS: It's very unsafe to use mac address in serial number. It's very easy to change.



来源:https://stackoverflow.com/questions/18021045/generating-serial-or-hex-code-for-product-licensing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!