Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Chroniccommand! AES Decrypter. This encrypts then decrypts some words!
- using System;
- using System.IO;
- using System.Text;
- using System.Security.Cryptography;
- public class RijndaelSimple
- {
- 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);
- // Start encrypting.
- cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
- // Finish encrypting.
- cryptoStream.FlushFinalBlock();
- byte[] cipherTextBytes = memoryStream.ToArray();
- // Close both streams.
- memoryStream.Close();
- cryptoStream.Close();
- string cipherText = Convert.ToBase64String(cipherTextBytes);
- // Return encrypted string.
- 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;
- }
- public class RijndaelSimpleTest
- {
- [STAThread]
- static void Main(string[] args)
- {
- string plainText = "My name is chroniccommand and this is a highly advanced AES encrypted file for a test to try to decrypt this very long plain text code and see how good my AES decryper can work"; // Setting plain text to encrypt
- string passPhrase = "Pas5ph@se"; // can be any string just change to your pass phrse
- string saltValue = "s@ltValue"; // Can be any salt value. Setting to example s@ltValue value
- string hashAlgorithm = "SHA1"; // can also be "MD5" instead of SHA1 but this depends on your hash
- int passwordIterations = 2; // can be any number... Setting to 2 by default
- string initVector = "@1B2c3D4e5F6g7h8"; // HASSSSS to be 16 wonderfull bytes
- int keySize = 256; // Can be 192, or 256
- Console.WriteLine(string.Format("Plaintext : {0}", plainText));
- string cipherText = RijndaelSimple.Encrypt(plainText,
- passPhrase,
- saltValue,
- hashAlgorithm,
- passwordIterations,
- initVector,
- keySize);
- Console.WriteLine(String.Format("Encrypted : {0}", cipherText));
- plainText = RijndaelSimple.Decrypt(cipherText,
- passPhrase,
- saltValue,
- hashAlgorithm,
- passwordIterations,
- initVector,
- keySize);
- Console.WriteLine(String.Format("Decrypted : {0}", plainText));
- //End of Decryption unit
- }
- }
- }
Add Comment
Please, Sign In to add comment