How to encode-decode URL!!

techexpert

Distinguished
Jul 18, 2008
1
0
18,510
0
This is the excample of how to encode-decode URL,through this code you can encode-decode a URL


public class UrlEncoderDecoder

{

public UrlEncoderDecoder()

{

// http://www.infysolutions.com

// TODO: Add constructor logic here

//

}

public static string TamperProofStringEncode(string value, string key)

{

System.Security.Cryptography.MACTripleDES mac3des = new System.Security.Cryptography.MACTripleDES();

System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();

mac3des.Key = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(key));

return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(value)) + '-' + Convert.ToBase64String(mac3des.ComputeHash(System.Text.Encoding.UTF8.GetBytes(value)));

}

public static string TamperProofStringDecode(string value, string key)

{

string dataValue = "";

string calcHash = "";

string storedHash = "";

System.Security.Cryptography.MACTripleDES mac3des = new System.Security.Cryptography.MACTripleDES();

System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();

mac3des.Key = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(key));

try

{

dataValue = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(value.Split('-')[0]));

storedHash = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(value.Split('-')[1]));

calcHash = System.Text.Encoding.UTF8.GetString(mac3des.ComputeHash(System.Text.Encoding.UTF8.GetBytes(dataValue)));

if (storedHash != calcHash)

{

throw new ArgumentException("Hash value does not match");

}

}

catch

{

throw new ArgumentException("Invalid TamperProofString");

}

return dataValue;

}

}


*****************************

Offshore Software Development

Offshore Outsourcing Software Development
 
Thread starter Similar threads Forum Replies Date
D Apps General Discussion 6
L Apps General Discussion 1
P Apps General Discussion 2
consptheory77 Apps General Discussion 6
N Apps General Discussion 2
D Apps General Discussion 5
K Apps General Discussion 3
P Apps General Discussion 2
S Apps General Discussion 1
J Apps General Discussion 1
Can You Help Me Please Apps General Discussion 1
wanamingo Apps General Discussion 3
WyomingKnott Apps General Discussion 2
N Apps General Discussion 1
C Apps General Discussion 12
Coreo Apps General Discussion 1
R Apps General Discussion 1
V Apps General Discussion 4
H Apps General Discussion 2
H Apps General Discussion 2

ASK THE COMMUNITY