Tom's Hardware > Forum > Applications > Other Software > How to encode-decode URL!!
Word :    Username :           
 

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

Sponsored Links
Register or log in to remove.

like doing things the hard way?

 

or the easy way?

 

http://uk2.php.net/urlencode

 
Code :
  1. <?php
  2. function urlcode()
  3. {
  4. $url = "www.tomshardware.co.uk";
  5. $url = urlencode($url);
  6. return $url;
  7. }
  8. ?>
 

EDIT

 

forgot the urldecode, silly me.

 

http://uk2.php.net/manual/en/function.urldecode.php

 
Code :
  1. <?php
  2. $url = urlcode();
  3. $url = urldecode($url);
  4. return $url;
  5. ?>
  


Message edited by Flakes on 07-18-2008 at 04:20:12 PM
Reply to Flakes
Tom's Hardware > Forum > Applications > Other Software > How to encode-decode URL!!
Go to:

There are 559 identified and unidentified users. To see the list of identified users, Click here.

Please mind

You are about to answer a thread that has been inactive for more than 6 months.
If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.

Add a reply Cancel
Sponsored links
  • Ask the community now
  • Publish
Ad
They won a badge
Join us in greeting them