50 mensajes Página 1 de 3
Imagen

Buenas después de picar algunas teclas he conseguido añadir algunas funciones mas a esta DLL y he añadido algunos tipos mas de encriptación para podáis hacer muchas mas cosas con esta DLL, espero que os guste...

Codigo:
UnmanagedExports.cs:
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using RGiesecke.DllExport;
using System.Collections.Generic;
using ManyMonkeys.Cryptography;
using System.Windows.Forms;
using BlowFishCS;
using CeoneCryptoA;
using CryptoRC4;

namespace Crypto
{
    internal static class CeoneCrypto
    {
       #region Others

       public static string GenerateSimpleSalt(int maxSize = 64)
       {
           var alphaSet = new char[64];
           alphaSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890#!".ToCharArray();
           var crypto = new RNGCryptoServiceProvider();
           var bytes = new byte[maxSize];
           crypto.GetBytes(bytes);
           var tempSB = new StringBuilder(maxSize);
           foreach (var b in bytes)
           {
               tempSB.Append(alphaSet[b % (alphaSet.Length)]);
           }
           return tempSB.ToString();
       }
       
       public static byte[] StrToByteArray(string str)
       {
           ASCIIEncoding encoding = new ASCIIEncoding();
           return encoding.GetBytes(str);
       }

       #endregion Others

       #region Encrypt and Decrypt Strings

       [DllExport("RijndaelEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RijndaelEncrypt(string plainText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
       {
           if (saltValue == null | saltValue == "")
           {
               saltValue = GenerateSimpleSalt(16);
           }
           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;
       }

       [DllExport("RijndaelDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RijndaelDecrypt(string cipherText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
       {
           if (saltValue == null | saltValue == "")
           {
               saltValue = GenerateSimpleSalt(16);
           }
           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;
       }

       [DllExport("AESEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string AESEncrypt(string value, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           SymmetricAlgorithm algorithm = SymmetricAlgorithm.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream())
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
               {
                   using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
                   {
                       writer.Write(value);
                   }
               }
               return Convert.ToBase64String(buffer.ToArray());
           }
       }
       
       [DllExport("AESDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string AESDecrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           SymmetricAlgorithm algorithm = SymmetricAlgorithm.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
               {
                   using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
                   {
                       return reader.ReadToEnd();
                   }
               }
           }
       }

       [DllExport("RC2Encrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC2Encrypt(string value, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           RC2 algorithm = RC2.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream())
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
               {
                   using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
                   {
                       writer.Write(value);
                   }
               }
               return Convert.ToBase64String(buffer.ToArray());
           }
       }

       [DllExport("RC2Decrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC2Decrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           RC2 algorithm = RC2.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
               {
                   using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
                   {
                       return reader.ReadToEnd();
                   }
               }
           }
       }

       [DllExport("RC4Encrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC4Encrypt(string text, string password)
       {
           RC4Engine myRC4Engine = new RC4Engine();
           myRC4Engine.EncryptionKey = password;
           myRC4Engine.InClearText = text;
           myRC4Engine.Encrypt();
           return myRC4Engine.CryptedText;
       }

       [DllExport("RC4Decrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC4Decrypt(string text, string password)
       {
           RC4Engine myRC4Engine = new RC4Engine();
           myRC4Engine.EncryptionKey = password;
           myRC4Engine.CryptedText = text;
           myRC4Engine.Decrypt();
           return myRC4Engine.InClearText;
       }

       [DllExport("DESEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string DESEncrypt(string value, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           DES algorithm = DES.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream())
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
               {
                   using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
                   {
                       writer.Write(value);
                   }
               }
               return Convert.ToBase64String(buffer.ToArray());
           }
       }

       [DllExport("DESDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string DESDecrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           DES algorithm = DES.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
               {
                   using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
                   {
                       return reader.ReadToEnd();
                   }
               }
           }
       }

       [DllExport("TripleDESEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TripleDESEncrypt(string value, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           TripleDES algorithm = TripleDES.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream())
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
               {
                   using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
                   {
                       writer.Write(value);
                   }
               }
               return Convert.ToBase64String(buffer.ToArray());
           }
       }

       [DllExport("TripleDESDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TripleDESDecrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           TripleDES algorithm = TripleDES.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
               {
                   using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
                   {
                       return reader.ReadToEnd();
                   }
               }
           }
       }

       [DllExport("TwofishEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TwofishEncrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           SymmetricAlgorithm algorithm = Twofish.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream())
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
               {
                   using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
                   {
                       writer.Write(text);
                   }
               }
               return Convert.ToBase64String(buffer.ToArray());
           }
       }
       
       [DllExport("TwofishDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TwofishDecrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
           SymmetricAlgorithm algorithm = Twofish.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
               {
                   using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
                   {
                       return reader.ReadToEnd();
                   }
               }
           }
       }

       [DllExport("BlowfishEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string BlowfishEncrypt(string text, string password)
       {
           BlowFish b = new BlowFish(password);
           return b.Encrypt_CBC(text);
       }

       [DllExport("BlowfishDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string BlowfishDecrypt(string text, string password)
       {
           BlowFish b = new BlowFish(password);
           return b.Decrypt_CBC(text);
       }

       [DllExport("XOREncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string XOREncrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16 + 93488);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt + 93488));
           SymmetricAlgorithm algorithm = XOR.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream())
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
               {
                   using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
                   {
                       writer.Write(text);
                   }
               }
               return Convert.ToBase64String(buffer.ToArray());
           }
       }

       [DllExport("XORDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string XORDecrypt(string text, string password, string salt)
       {
           if (salt == null | salt == "")
           {
               salt = GenerateSimpleSalt(16 + 93488);
           }
           DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt + 93488));
           SymmetricAlgorithm algorithm = XOR.Create();
           byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);
           using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
           {
               using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
               {
                   using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
                   {
                       return reader.ReadToEnd();
                   }
               }
           }
       }

       [DllExport("RSAEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RSAEncrypt(string text, string password) //, string password, string salt
       {
           CspParameters cspp = new CspParameters();
           cspp.KeyContainerName = password;

           RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspp);
           rsa.PersistKeyInCsp = true;

           byte[] bytes = rsa.Encrypt(System.Text.UTF8Encoding.UTF8.GetBytes(text), true);

           return BitConverter.ToString(bytes);
       }

       [DllExport("RSADecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RSADecrypt(string text, string password) //, string password, string salt
       {
           CspParameters cspp = new CspParameters();
           cspp.KeyContainerName = password;

           RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspp);
           rsa.PersistKeyInCsp = true;
           
           string[] decryptArray = text.Split(new string[] { "-" }, StringSplitOptions.None);
           byte[] decryptByteArray = Array.ConvertAll<string, byte>(decryptArray, (s => Convert.ToByte(byte.Parse(s, System.Globalization.NumberStyles.HexNumber))));
           byte[] bytes = rsa.Decrypt(decryptByteArray, true);

           return System.Text.UTF8Encoding.UTF8.GetString(bytes);
       }

       [DllExport("CustomEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string CustomEncrypt(string PlainText, string Key)
       {
           return EncDec.EncryptString(PlainText, Key);
       }

       [DllExport("CustomDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string CustomDecrypt(string EncryptedText, string Key)
       {
           return EncDec.DecryptString(EncryptedText, Key); ;
       }

       #endregion Encrypt and Decrypt Strings

       #region Encrypt and Decrypt Files

       [DllExport("AESEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string AESEncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

           SymmetricAlgorithm alg = SymmetricAlgorithm.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateEncryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);
           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }
       
       [DllExport("AESDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string AESDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
           SymmetricAlgorithm alg = SymmetricAlgorithm.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);

           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("RijndaelEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RijndaelEncryptFile(string originalFile, string encryptedFile, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           if (saltValue == null | saltValue == "")
           {
               saltValue = GenerateSimpleSalt(16);
           }
           byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
           byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);

           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           byte[] plainTextBytes = bytes;

           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();

           fsOut.Write(cipherTextBytes, 0, cipherTextBytes.Length);
           fsOut.Close();
           
           return "";
       }

       [DllExport("RijndaelDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RijndaelDecryptFile(string encryptedFile, string decryptedFile, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           if (saltValue == null | saltValue == "")
           {
               saltValue = GenerateSimpleSalt(16);
           }
           
           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
           byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);

           byte[] cipherTextBytes = bytes;

           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();

           fsOut.Write(plainTextBytes, 0, plainTextBytes.Length);
           fsOut.Close();

           return "";
       }

       [DllExport("RC2EncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC2EncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

           RC2 alg = RC2.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);

           //byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
           //byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
           //ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateEncryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);
           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("RC2DecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC2DecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
           RC2 alg = RC2.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);


           CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);

           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("RC4EncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC4EncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           RC4Engine myRC4Engine = new RC4Engine();
           myRC4Engine.EncryptionKey = keyFile;
           byte[] encryptedbyte = myRC4Engine.EncryptToByte(bytes);

           fsOut.Write(encryptedbyte, 0, encryptedbyte.Length);
           fsOut.Close();

           return "";
       }

       [DllExport("RC4DecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RC4DecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           RC4Engine myRC4Engine = new RC4Engine();
           myRC4Engine.EncryptionKey = keyFile;
           byte[] decryptedbyte = myRC4Engine.DecryptToByte(bytes);

           fsOut.Write(decryptedbyte, 0, decryptedbyte.Length);
           fsOut.Close();

           return "";
       }

       [DllExport("DESEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string DESEncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

           DES alg = DES.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateEncryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);
           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("DESDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string DESDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
           DES alg = DES.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);


           CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);

           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("TripleDESEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TripleDESEncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

           TripleDES alg = TripleDES.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3); //16);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3); //8);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateEncryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);
           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("TripleDESDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TripleDESDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
           TripleDES alg = TripleDES.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3); //16);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3); //8);


           CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);

           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("TwofishEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TwofishEncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

           SymmetricAlgorithm alg = Twofish.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateEncryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);
           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("TwofishDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string TwofishDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
           SymmetricAlgorithm alg = Twofish.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);


           CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);

           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("XOREncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string XOREncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

           SymmetricAlgorithm alg = XOR.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateEncryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);
           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("XORDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string XORDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyFile,
               new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
           SymmetricAlgorithm alg = XOR.Create();
           alg.Key = pdb.GetBytes(alg.KeySize >> 3);
           alg.IV = pdb.GetBytes(alg.BlockSize >> 3);

           CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

           int bufferLen = 4096;
           byte[] buffer = new byte[bufferLen];
           int bytesRead;

           do
           {
               bytesRead = fsIn.Read(buffer, 0, bufferLen);

               cs.Write(buffer, 0, bytesRead);

           } while (bytesRead != 0);

           cs.Close();
           fsIn.Close();
           return "";
       }

       [DllExport("CustomEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string CustomEncryptFile(string originalFile, string decryptedFile, string keyFile)
       {
           EncDec.EncryptFile(originalFile, decryptedFile, keyFile);
           return "";
       }

       [DllExport("CustomDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string CustomDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           EncDec.DecryptFile(encryptedFile, decryptedFile, keyFile);
           return "";
       }

       [DllExport("VernamEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string VernamEncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           // Read in the bytes from the original file:
           byte[] originalBytes;
           using (FileStream fs = new FileStream(originalFile, FileMode.Open))
           {
               originalBytes = new byte[fs.Length];
               fs.Read(originalBytes, 0, originalBytes.Length);
           }

           // Create the one time key for encryption. This is done
           // by generating random bytes that are of the same lenght
           // as the original bytes:
           byte[] keyBytes = new byte[originalBytes.Length];
           Random random = new Random();
           random.NextBytes(keyBytes);

           // Write the key to the file:
           using (FileStream fs = new FileStream(keyFile, FileMode.Create))
           {
               fs.Write(keyBytes, 0, keyBytes.Length);
           }

           // Encrypt the data with the Vernam-algorithm:
           byte[] encryptedBytes = new byte[originalBytes.Length];
           //DoVernam(originalBytes, keyBytes, ref encryptedBytes);

           byte[] inBytes = originalBytes;
           byte[] outBytes = encryptedBytes;

           // Check arguments:
           if ((inBytes.Length != keyBytes.Length) ||
               (keyBytes.Length != outBytes.Length))
               throw new ArgumentException("Byte-array are not of same length");

           // Encrypt/decrypt by XOR:
           for (int i = 0; i < inBytes.Length; i++)
               outBytes[i] = (byte)(inBytes[i] ^ keyBytes[i]);

           // Write the encrypted file:
           using (FileStream fs = new FileStream(encryptedFile, FileMode.Create))
           {
               fs.Write(encryptedBytes, 0, encryptedBytes.Length);
           }
           return "";
       }

       [DllExport("VernamDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string VernamDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           // Read in the encrypted bytes:
           byte[] encryptedBytes;
           using (FileStream fs = new FileStream(encryptedFile, FileMode.Open))
           {
               encryptedBytes = new byte[fs.Length];
               fs.Read(encryptedBytes, 0, encryptedBytes.Length);
           }

           // Read in the key:
           byte[] keyBytes;
           using (FileStream fs = new FileStream(keyFile, FileMode.Open))
           {
               keyBytes = new byte[fs.Length];
               fs.Read(keyBytes, 0, keyBytes.Length);
           }

           // Decrypt the data with the Vernam-algorithm:
           byte[] decryptedBytes = new byte[encryptedBytes.Length];
           //DoVernam(encryptedBytes, keyBytes, ref decryptedBytes);

           byte[] inBytes = encryptedBytes;
           byte[] outBytes = decryptedBytes;

           // Check arguments:
           if ((inBytes.Length != keyBytes.Length) ||
               (keyBytes.Length != outBytes.Length))
               throw new ArgumentException("Byte-array are not of same length");

           // Encrypt/decrypt by XOR:
           for (int i = 0; i < inBytes.Length; i++)
               outBytes[i] = (byte)(inBytes[i] ^ keyBytes[i]);

           // Write the decrypted file:
           using (FileStream fs = new FileStream(decryptedFile, FileMode.Create))
           {
               fs.Write(decryptedBytes, 0, decryptedBytes.Length);
           }
           return "";
       }

       #endregion Encrypt and Decrypt Files

       #region FuncionaMAL
       [DllExport("BlowfishEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string BlowfishEncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           BlowFish b = new BlowFish(keyFile);
           byte[] encryptedbyte = b.Encrypt_ECB(bytes);

           fsOut.Write(encryptedbyte, 0, encryptedbyte.Length);
           fsOut.Close();

           return "";
       }


       [DllExport("BlowfishDecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string BlowfishDecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           BlowFish b = new BlowFish(keyFile);
           byte[] encryptedbyte = b.Decrypt_ECB(bytes);

           fsOut.Write(encryptedbyte, 0, encryptedbyte.Length);
           fsOut.Close();

           return "";
       }

       [DllExport("RSAEncryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RSAEncryptFile(string originalFile, string encryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(originalFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(encryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           CspParameters cspp = new CspParameters();
           cspp.KeyContainerName = keyFile;
           
           RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspp);
           rsa.PersistKeyInCsp = true;

           byte[] encryptedbyte = rsa.Encrypt(bytes, true);

           fsOut.Write(encryptedbyte, 0, encryptedbyte.Length);
           fsOut.Close();

           return "";
       }

       [DllExport("RSADecryptFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string RSADecryptFile(string encryptedFile, string decryptedFile, string keyFile)
       {
           FileStream fsIn = new FileStream(encryptedFile, FileMode.Open, FileAccess.Read);
           FileStream fsOut = new FileStream(decryptedFile, FileMode.OpenOrCreate, FileAccess.Write);

           byte[] bytes = new byte[fsIn.Length];
           fsIn.Read(bytes, 0, Convert.ToInt32(fsIn.Length));
           fsIn.Close();

           CspParameters cspp = new CspParameters();
           cspp.KeyContainerName = keyFile;

           RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspp);
           rsa.PersistKeyInCsp = true;

           byte[] encryptedbyte = rsa.Decrypt(bytes, true);

           fsOut.Write(encryptedbyte, 0, encryptedbyte.Length);
           fsOut.Close();

           return "";
       }
       #endregion FuncionaMAL

       #region About

       [DllExport("About", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
       static string About()
       {
           Form1 About = new Form1();
           About.Show();
           return "";
       }

       #endregion About
    }
}
Parsed in 0.115 seconds, using GeSHi 1.0.8.9


Descarga:
Contenido Oculto: ON
	<br />Usted necesita responder en este tema para ver el contenido oculto.


Imagen
Pues Ceone, me quito el sombrero, que sos un mago para esto, muy agardecido con voz

un saludo y felices pascuas desde Amalfi-Antioquia-Colombia

Sattel
Sattel desde Amalfi Antioquia Colombia
Medellin Colombia
La ciudad mas innovadora del mundo!!!!!!!!
thanks
Imagen
molable!
Thank you
Imagen
Thanks
thanks
thanks :)

thanks

nice ceone. un genio pero necesito lo k t pedi !

nice ceone. un genio pero necesito lo k t pedi !
gracias

omisterioo escribió: nice ceone. un genio pero necesito lo k t pedi !


que?

good job ceone

observando

thanks

like :pc: :friends:

Gracias

lets try this ,thank you !...
50 mensajes Página 1 de 3

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 1 invitado

cron