Click here to Skip to main content
12,246,406 members (39,774 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

70.8K views
1.9K downloads
40 bookmarked
Posted

FrameControl - Framework for creating web applications

, 25 Jul 2003
FrameControl is a framework that contains the code common for most of the web applications.
FrameControl1.dll
doc
banner.jpg
darkcorner.jpg
FrameControl1
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
banner.jpg
darkcorner.jpg
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
obj
Debug
temp
TempPE
Release
FrameControl1.dll
FrameControl1.projdata
temp
TempPE
FrameControl1.csproj.user
FrameControl_install.zip
using System;
using System.Security.Cryptography;
using System.Text;

namespace JobMorning
{
	
	public class CryptoEncrypt
	{
		public static string encrypt (string original)
		{
			string                         encrypted, password;
			TripleDESCryptoServiceProvider des;
			MD5CryptoServiceProvider       hashmd5;
			byte[]                         pwdhash, buff;

			//create a secret password. the password is used to encrypt
			//and decrypt strings. Without the password, the encrypted
			//string cannot be decrypted and is just garbage. You must
			//use the same password to decrypt an encrypted string as the
			//string was originally encrypted with.
			password = "urayasu";
            
			//generate an MD5 hash from the password. 
			//a hash is a one way encryption meaning once you generate
			//the hash, you cant derive the password back from it.
			hashmd5 = new MD5CryptoServiceProvider();
			pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));
			hashmd5 = null;

			//implement DES3 encryption
			des = new TripleDESCryptoServiceProvider();

			//the key is the secret password hash.
			des.Key = pwdhash;

			//the mode is the block cipher mode which is basically the
			//details of how the encryption will work. There are several
			//kinds of ciphers available in DES3 and they all have benefits
			//and drawbacks. Here the Electronic Codebook cipher is used
			//which means that a given bit of text is always encrypted
			//exactly the same when the same password is used.
			des.Mode = CipherMode.ECB; //CBC, CFB


			//----- encrypt an un-encrypted string ------------
			//the original string, which needs encrypted, must be in byte
			//array form to work with the des3 class. everything will because
			//most encryption works at the byte level so you'll find that
			//the class takes in byte arrays and returns byte arrays and
			//you'll be converting those arrays to strings.
			buff = ASCIIEncoding.ASCII.GetBytes(original);

			//encrypt the byte buffer representation of the original string
			//and base64 encode the encrypted string. the reason the encrypted
			//bytes are being base64 encoded as a string is the encryption will
			//have created some weird characters in there. Base64 encoding
			//provides a platform independent view of the encrypted string 
			//and can be sent as a plain text string to wherever.
			encrypted = Convert.ToBase64String(
				des.CreateEncryptor().TransformFinalBlock(buff, 0, buff.Length)
				);


			//cleanup
			des = null;

			return encrypted;

		}

	}
	
	/// <summary>
	/// Summary description for CryptoDecrypt.
	/// </summary>
	public class CryptoDecrypt
	{
		public static string Decrypt (string encrypted)
		{
			string                         Decrypted, password;
			TripleDESCryptoServiceProvider des;
			MD5CryptoServiceProvider       hashmd5;
			byte[]                         pwdhash, buff;

			//create a secret password. the password is used to encrypt
			//and Decrypt strings. Without the password, the encrypted
			//string cannot be Decrypted and is just garbage. You must
			//use the same password to Decrypt an encrypted string as the
			//string was originally encrypted with.
			password = "urayasu";
            
			//generate an MD5 hash from the password. 
			//a hash is a one way encryption meaning once you generate
			//the hash, you cant derive the password back from it.
			hashmd5 = new MD5CryptoServiceProvider();
			pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));
			hashmd5 = null;

			//implement DES3 encryption
			des = new TripleDESCryptoServiceProvider();
			//the key is the secret password hash.
			des.Key = pwdhash;

			//the mode is the block cipher mode which is basically the
			//details of how the encryption will work. There are several
			//kinds of ciphers available in DES3 and they all have benefits
			//and drawbacks. Here the Electronic Codebook cipher is used
			//which means that a given bit of text is always encrypted
			//exactly the same when the same password is used.
			des.Mode = CipherMode.ECB; //CBC, CFB

			//whenever you Decrypt a string, you must do everything you
			//did to encrypt the string, but in reverse order. To encrypt,
			//first a normal string was des3 encrypted into a byte array
			//and then base64 encoded for reliable transmission. So, to 
			//Decrypt this string, first the base64 encoded string must be 
			//decoded so that just the encrypted byte array remains.
			buff = Convert.FromBase64String(encrypted);

			//Decrypt DES 3 encrypted byte buffer and return ASCII string
			Decrypted = ASCIIEncoding.ASCII.GetString(
				des.CreateDecryptor().TransformFinalBlock(buff, 0, buff.Length)
				);

			//cleanup
			des = null;

			return Decrypted;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

S. Jehan
Japan Japan
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 26 Jul 2003
Article Copyright 2003 by S. Jehan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid