|
-
Jan 17th, 2005, 01:50 PM
#1
Thread Starter
PowerPoster
encrypt QS
Hi there. i have googled for this but unfortunatly didnt come with "working" solutions
i was wondering, how is it possible to encrypt and decrypt query strings in asp.net? is it possible?
-
Jan 17th, 2005, 03:18 PM
#2
Addicted Member
Re: encrypt QS
You can encrypt and decrypt strings using the System.Security.Cryptography class in .Net. Take a look here:
http://www.codeproject.com/dotnet/crypto_net.asp
A little complicating at first but you eventually get the hang of it :/
-
Jan 17th, 2005, 03:19 PM
#3
Thread Starter
PowerPoster
Re: encrypt QS
dnt like those codes
-
Jan 17th, 2005, 03:27 PM
#4
Addicted Member
Re: encrypt QS
hehe, well thats the proper way to encrypt data if you want to be safe (well as far as I know)
The code is all there, just copy paste, stick it into some functions and pass it your string. Simple
-
Jan 18th, 2005, 07:42 AM
#5
Thread Starter
PowerPoster
Re: encrypt QS
surprise surprise - code doesnt work well
doesnt like this line:
SymmetricAlgorithm Like DES mCryptProv = SymmetricAlgorithm.Create("Rijndael")
doesnt like the first code: "SymmetricAlgorithm is a type and cannot be used in an expression"
-
Jan 18th, 2005, 08:41 AM
#6
Addicted Member
Re: encrypt QS
Thats cos it looks like they messed up the comments
SymmetricAlgorithm Like DES -->> should be part of the comments on the line above
I'm guessing the line should rather say:
mCryptProv = SymmetricAlgorithm.Create("Rijndael")
-
Jan 18th, 2005, 01:02 PM
#7
Frenzied Member
Re: encrypt QS
PHP Code:
public class Crypto
{
#region Crypto
internal static string cryptKey = "SiTdOwNaNdShUtUpYoUbIgBaLlEd****";
internal static string cryptIV = "iHaTe****InGdOgS";
internal static System.Security.Cryptography.RijndaelManaged rj;
internal static string Encrypt(string value)
{
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(value);
byte[] key = System.Text.ASCIIEncoding.ASCII.GetBytes(cryptKey);
byte[] iv = System.Text.ASCIIEncoding.ASCII.GetBytes(cryptIV);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
rj = new System.Security.Cryptography.RijndaelManaged();
rj.Key = key;
rj.IV = iv;
System.Security.Cryptography.ICryptoTransform encrypt = rj.CreateEncryptor();
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, encrypt, System.Security.Cryptography.CryptoStreamMode.Write);
cs.Write(b, 0, b.Length);
cs.FlushFinalBlock();
byte[] bo = ms.GetBuffer();
int i = 0;
for(i = 0; i < bo.Length; i++)
{
if(bo[i] == 0) break;
}
return System.Convert.ToBase64String(bo, 0, i);
}
internal static string Decrypt(string value)
{
byte[] b = System.Convert.FromBase64String(value);
byte[] key = System.Text.ASCIIEncoding.ASCII.GetBytes(cryptKey);
byte[] iv = System.Text.ASCIIEncoding.ASCII.GetBytes(cryptIV);
System.IO.MemoryStream ms = new System.IO.MemoryStream(b, 0, b.Length);
rj = new System.Security.Cryptography.RijndaelManaged();
rj.Key = key;
rj.IV = iv;
System.Security.Cryptography.ICryptoTransform encrypt = rj.CreateDecryptor();
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, encrypt, System.Security.Cryptography.CryptoStreamMode.Read);
System.IO.StreamReader sr = new System.IO.StreamReader(cs);
return sr.ReadToEnd();
}
#endregion
}
This works, but the encryption has a flaw it has returned items that can't be decrypted.
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|