有没有办法生成类似的串行/十六进制代码:xxxx-xxxx-xxxx-xxxx-xxxx-xxxx 用java api?当产品破译它应该能够提取的代码时
将根据上述因素生成代码。我尝试使用私钥/公钥 RSA / ECB / PKCS1Padding 。然后转换为HEX,但它需要 4096 的私钥六十六,生成的十六进制代码太长了!
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;
}
...
...
...
}
答案 0 :(得分:1)
使用自定义数据,您无法创建固定长度的序列号。但您可以将序列号与信息相关联,例如在数据库中。简单的序列号生成器:
String serial = UUID.randomUUID().toString().toUpperCase();
System.out.println(serial);
PS:在序列号中使用mac地址是非常不安全的。它很容易改变。