c# - How to convert string to a activation key(format xxxx-xxxx-xxxx-xxxx-xxxx) and extract original string from activation key -
i looking way create string in format of xxxx-xxxx-xxxx-xxxx-xxxx string , if have string can extract original string string in c#. have search on google found solution convert string required format don't original string output. there way achieve it.
i found below sample of md5 converts string in desired format can't convert orignal string.
private static string gethash(string s) { md5 sec = new md5cryptoserviceprovider(); asciiencoding enc = new asciiencoding(); byte[] bt = enc.getbytes(s); return gethexstring(sec.computehash(bt)); } private static string gethexstring(byte[] bt) { int tmp = (int)'a'; string s = string.empty; (int = 0; < bt.length; i++) { byte b = bt[i]; int n, n1, n2; n = (int)b; n1 = n & 15; n2 = (n >> 4) & 15; if (n2 > 9) { tmp = 0; tmp = (n2 - 10 + (int)'a'); s += ((char)(n2 - 10 + (int)'a')).tostring(); } else s += n2.tostring(); if (n1 > 9) { tmp = 0; tmp = (n1 - 10 + (int)'a'); s += ((char)(n1 - 10 + (int)'a')).tostring(); } else s += n1.tostring(); if ((i + 1) != bt.length && (i + 1) % 2 == 0) s += "-"; } return s; }
you should use sort of encryption, can decrypt original string again. md5 hashing function, means after hashing string there no (algorithmic) function can reverse hash original string.
once you've encrypted plaintext ciphertext using encryption function, can format encrypted string in desired format like, long reversible function. let's encrypted string "123456789", you'd format let's say: "12 - 3456 - 6 - 789".
considering know after how many characters added separator, can reverse key ciphertext , use decryption method obtain original string.
on side note: assume need kind of email verification. method in more simple way create hash email ( or whatever you're verifying) salt, , send string email user. since saved activation key database can couple key corresponding email address.
Comments
Post a Comment