public class LicenseKey
{
public static void main(String[] args) {
String userName = "John Doe";
String productKey = "1002-1";
String versionNumber = "1";
String licenseKey = createLicenseKey(userName, productKey, versionNumber);
System.out.println("licenseKey = " + licenseKey);
//License Key should be similar to this: 7F4727-423B69-4275C6-2E8012-38EC2F-663D65-5E68
}
public static String createLicenseKey(String userName, String productKey, String versionNumber) {
String s = userName + "|" + productKey + "|" + versionNumber;
HashFunction hashFunction = Hashing.sha1();
HashCode hashCode = hashFunction.hashUnencodedChars(s);
String upper = hashCode.toString().toUpperCase();
return group(upper);
}
private static String group(String s) {
String result = "";
for (int i=0; i < s.length(); i++) {
if (i%6==0 && i > 0) {
result += '-';
}
result += s.charAt(i);
}
return result;
}
}
This certainly works, but I don't understand how to reverse it. How do I take the licenseKey string and regain the String sequence: John Doe|1002-1|1
Please advise,
Alan
--
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/c5952520-2a5d-4ebb-91a6-d2397e4c0208%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/d9e5c6e0-c92a-4564-a565-cac6db44d225%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/d9e5c6e0-c92a-4564-a565-cac6db44d225%40googlegroups.com.
Well, then perhaps license keys are created using some other method? I'm just trying to figure out how one validates a license key? If I can't decrypt a hashcode, then maybe some other method is used?