Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[Source] AES Encryption [C#]

Here is source of AES encryption algorithm written in C#

How to use this class

- string plainText - string you want encrypt
- chiperText - string you want decrypt
- passPharse - what ever password you want
- saltValue - can be any string, act like secon password
- hashAlgorithm - can be SHA1, MD5, SHA512 etc...
- passwordIterations - any number
- initVector - must be "@1B2c3D4e5F6g7H8";
- keySize - can be 128,192,256

Code
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;

namespace Encryption
{
    public class AES
    {
        public static string Encrypt(string plainText,
                                string passPhrase,
                                string saltValue,
                                string hashAlgorithm,
                                int passwordIterations,
                                string initVector,
                                int keySize)
        {

            byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
            byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
            byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
        
            PasswordDeriveBytes password = new PasswordDeriveBytes(
                                                            passPhrase,
                                                            saltValueBytes,
                                                            hashAlgorithm,
                                                            passwordIterations);


            byte[] keyBytes = password.GetBytes(keySize / 8);

            RijndaelManaged symmetricKey = new RijndaelManaged();
            symmetricKey.Mode = CipherMode.CBC;
            ICryptoTransform encryptor = symmetricKey.CreateEncryptor(
                                                             keyBytes,
                                                             initVectorBytes);
            MemoryStream memoryStream = new MemoryStream();
      
            CryptoStream cryptoStream = new CryptoStream(memoryStream,
                                                         encryptor,
                                                         CryptoStreamMode.Write);

            cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
            cryptoStream.FlushFinalBlock();

            byte[] cipherTextBytes = memoryStream.ToArray();

            memoryStream.Close();
            cryptoStream.Close();

            string cipherText = Convert.ToBase64String(cipherTextBytes);

            return cipherText;
        }

        public static string Decrypt(string cipherText,
                                     string passPhrase,
                                     string saltValue,
                                     string hashAlgorithm,
                                     int passwordIterations,
                                     string initVector,
                                     int keySize)
        {
            byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
            byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);

            byte[] cipherTextBytes = Convert.FromBase64String(cipherText);

            PasswordDeriveBytes password = new PasswordDeriveBytes(
                                                            passPhrase,
                                                            saltValueBytes,
                                                            hashAlgorithm,
                                                            passwordIterations);

            byte[] keyBytes = password.GetBytes(keySize / 8);

        
            RijndaelManaged symmetricKey = new RijndaelManaged();

            symmetricKey.Mode = CipherMode.CBC;

            ICryptoTransform decryptor = symmetricKey.CreateDecryptor(
                                                             keyBytes,
                                                             initVectorBytes);

          
            MemoryStream memoryStream = new MemoryStream(cipherTextBytes);

            CryptoStream cryptoStream = new CryptoStream(memoryStream,
                                                          decryptor,
                                                          CryptoStreamMode.Read);

            byte[] plainTextBytes = new byte[cipherTextBytes.Length];

            int decryptedByteCount = cryptoStream.Read(plainTextBytes,
                                                       0,
                                                       plainTextBytes.Length);

            memoryStream.Close();
            cryptoStream.Close();

            string plainText = Encoding.UTF8.GetString(plainTextBytes,
                                                       0,
                                                       decryptedByteCount);
            return plainText;
        }

    }
}

Download link: http://www.multiupload.com/9IMBEJETR6
Good job, if you made this....
(Sep 17, 2010 10:44 AM)pr3fix Wrote:  Good job, if you made this....

Thanks...!
🙂

(too short message)
Just to refresh this thread.
BUMP!
http://www.discussweb.com/other-web-prog...-data.html
at least give credits if your gonna leech...
yea bro give credits man
shorty msg
Credits to: H2o
Can't update first post!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by neonbytesJan 8, 2021 04:09 PM 10 350 Jan 8, 2021 04:09 PM
Last Post: poker
[C] by TarikBrt69Oct 1, 2020 01:57 AM 6 377 Oct 1, 2020 01:57 AM
Last Post: mike.vronsky
[C#] by draxyeeDec 28, 2019 12:24 PM 5 305 Dec 28, 2019 12:24 PM
Last Post: MavenGradle