.net - C# token parsing -


i combine date , user email 1 base64 string, works this:

public string generateuniquetoken(string email) {     byte[] time = bitconverter.getbytes(datetime.utcnow.tobinary());     byte[] key = encoding.ascii.getbytes(email);     string encoded = convert.tobase64string(time.concat(key).toarray());     return criptographyservice.encrypt(encoded); } 

i parse email decoded string, getting together:

public string tokenuservalid(string token) {     string decrypted = criptographyservice.decrypt(token);     byte[] data = convert.frombase64string(decrypted);     return encoding.default.getstring(data); } 

i in form this:

\�����hmy.email@gmail.com

as know length of date can read time , email separately byte[]

//combine time , email byte[] time = bitconverter.getbytes(datetime.utcnow.tobinary()); byte[] key = encoding.ascii.getbytes("scottrobinson@notmyemail.com); string encoded = convert.tobase64string(time.concat(key).toarray());  //read time , email byte[] data = convert.frombase64string(encoded); datetime date =  datetime.frombinary(bitconverter.toint64(data.take(8).toarray(), 0)); //read date string email  = encoding.default.getstring(data.skip(8).toarray()); //read email 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -