TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
krisstephenson
NA
1
0
C# to vb.net
Jun 3 2004 11:47 AM
Can anyone convert this code to vb.net for me or at least explain the syntax? public class SecureQueryString : NameValueCollection { public SecureQueryString() : base() {} public SecureQueryString(string encryptedString) { deserialize(decrypt(encryptedString)); // Compare the Expiration Time with the current Time to ensure // that the queryString has not expired. if (DateTime.Compare(ExpireTime, DateTime.Now) < 0) { throw new ExpiredQueryStringException(); } } ///
/// Returns the encrypted query string. ///
public string EncryptedString { get { return HttpUtility.UrlEncode(encrypt(serialize())); } } private DateTime _expireTime = DateTime.MaxValue; ///
/// The timestamp in which the EncryptedString should expire ///
public DateTime ExpireTime { get { return _expireTime; } set { _expireTime = value; } } ///
/// Returns the EncryptedString property. ///
public override string ToString() { return EncryptedString; } ///
/// Encrypts a serialized query string ///
private string encrypt(string serializedQueryString) { byte[] buffer = Encoding.ASCII.GetBytes(serializedQueryString); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider(); des.Key = MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey)); des.IV = IV; return Convert.ToBase64String( des.CreateEncryptor().TransformFinalBlock( buffer, 0, buffer.Length ) ); } ///
/// Decrypts a serialized query string ///
private string decrypt(string encryptedQueryString) { try { byte[] buffer = Convert.FromBase64String(encryptedQueryString); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider(); des.Key = MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey)); des.IV = IV; return Encoding.ASCII.GetString( des.CreateDecryptor().TransformFinalBlock( buffer, 0, buffer.Length ) ); } catch (CryptographicException) { throw new InvalidQueryStringException(); } catch (FormatException) { throw new InvalidQueryStringException(); } } ///
/// Deserializes a decrypted query string and stores it /// as name/value pairs. ///
private void deserialize(string decryptedQueryString) { string[] nameValuePairs = decryptedQueryString.Split('&'); for (int i=0; i
/// Serializes the underlying NameValueCollection as a QueryString /// private string serialize() { StringBuilder sb = new StringBuilder(); foreach (string key in base.AllKeys) { sb.Append(key); sb.Append('='); sb.Append(base[key]); sb.Append('&'); } // Append timestamp sb.Append(timeStampKey); sb.Append('='); sb.Append(_expireTime); return sb.ToString(); } private const string timeStampKey = "__TimeStamp__"; // The key used for generating the encrypted string private const string cryptoKey = "ChangeThis!"; // The Initialization Vector for the DES encryption routine private readonly byte[] IV = new byte[8] {240, 3, 45, 29, 0, 76, 173, 59}; }
Reply
Answers (
1
)
Problem with adding a reference to a shared assembly
Trouble changing textcolor