I am looking for a way to create string in format of xxxx-xxxx-xxxx-xxxx-xxxx from string and if I have that string I can extract original string from that string in C#. I have search on google I found some solution which convert string to the required format but they don't get back the original string from the output. Is there any way to achieve it.
I found below sample of MD5 which converts string in my desired format but I can't convert that back to 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;
for (int i = 0; i < 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;
}