有没有办法使用java api生成类似的串行/十六进制代码:xxxx-xxxx-xxxx-xxxx-xxxx-xxxx?当产品破译它应该能够提取的代码时
- 姓名
- 有效性
- MAC地址
- 附加信息
将根据上述因素生成代码。我尝试使用私钥/公钥进行RSA/ECB/PKCS1Padding 。然后转成HEX,但是需要4096的私钥sixe,而且生成的hex码太长!
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;
}
...
...
...
}