问题描述
有没有办法生成串行/十六进制代码,如:xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
使用java api?当产品解密代码时,应该可以提取
Is there way to generate serial/hex code something like: xxxx-xxxx-xxxx-xxxx-xxxx-xxxxusing java api? when product decipher the code it should able to extract
- 名称
- 有效性
- Mac地址
- 其他信息
- Name
- Validity
- Mac Address
- Additional information
代码将基于以上因素。我试图用私钥/公钥 RSA / ECB / PKCS1Padding 。然后转换为HEX,但需要4096的私钥六十六进制,并且生成的十六进制代码太长!
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 protected];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;
}
...
...
...
}
推荐答案
使用自定义数据,您无法创建固定长度的序列号。但是,您可以将序列号与信息相关联。在数据库中。简单的序列号生成器:
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:在序列号中使用mac地址是非常不安全的。这很容易改变。
PS: It's very unsafe to use mac address in serial number. It's very easy to change.
这篇关于生成产品许可的串行或十六进制代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!