Results 1 to 7 of 7

Thread: encrypt QS

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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?

  2. #2
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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 :/

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: encrypt QS

    dnt like those codes

  4. #4
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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"

  6. #6
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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")

  7. #7
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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[] 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(msencryptSystem.Security.Cryptography.CryptoStreamMode.Write);

                
    cs.Write(b0b.Length);
                
    cs.FlushFinalBlock();

                
    byte[] bo ms.GetBuffer();
                
    int i 0;
                for(
    0bo.Lengthi++)
                {
                    if(
    bo[i] == 0) break;
                }
                return 
    System.Convert.ToBase64String(bo0i);
            }
            
    internal static string Decrypt(string value)
            {
                
    byte[] 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(b0b.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(msencryptSystem.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
  •  



Click Here to Expand Forum to Full Width