All these encryptions are ported off the ones posted in Prototypes thread.
I simply ported them to C#:
DES:
AES:
RSA:
Enjoy!
I simply ported them to C#:
DES:
Code
public string DES_Encrypt(string input, string pass)
{
System.Security.Cryptography.DESCryptoServiceProvider DES = new System.Security.Cryptography.DESCryptoServiceProvider();
System.Security.Cryptography.MD5CryptoServiceProvider Hash_DES = new System.Security.Cryptography.MD5CryptoServiceProvider();
string encrypted = "";
try
{
byte[] hash = new byte[8];
byte[] temp = Hash_DES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass));
Array.Copy(temp, 0, hash, 0, 8);
DES.Key = hash;
DES.Mode = System.Security.Cryptography.CipherMode.ECB;
System.Security.Cryptography.ICryptoTransform DESEncrypter = DES.CreateEncryptor();
byte[] Buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(input);
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length));
return encrypted;
}
catch (Exception ex)
{
}
return encrypted;
}
public string DES_Decrypt(string input, string pass)
{
System.Security.Cryptography.DESCryptoServiceProvider DES = new System.Security.Cryptography.DESCryptoServiceProvider();
System.Security.Cryptography.MD5CryptoServiceProvider Hash_DES = new System.Security.Cryptography.MD5CryptoServiceProvider();
string decrypted = "";
try
{
byte[] hash = new byte[8];
byte[] temp = Hash_DES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass));
Array.Copy(temp, 0, hash, 0, 8);
DES.Key = hash;
DES.Mode = System.Security.Cryptography.CipherMode.ECB;
System.Security.Cryptography.ICryptoTransform DESDecrypter = DES.CreateDecryptor();
byte[] Buffer = Convert.FromBase64String(input);
decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length));
return decrypted;
}
catch (Exception ex)
{
}
return decrypted;
}AES:
Code
public string AES_Encrypt(string input, string pass)
{
System.Security.Cryptography.RijndaelManaged AES = new System.Security.Cryptography.RijndaelManaged();
System.Security.Cryptography.MD5CryptoServiceProvider Hash_AES = new System.Security.Cryptography.MD5CryptoServiceProvider();
string encrypted = "";
try
{
byte[] hash = new byte[32];
byte[] temp = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass));
Array.Copy(temp, 0, hash, 0, 16);
Array.Copy(temp, 0, hash, 15, 16);
AES.Key = hash;
AES.Mode = System.Security.Cryptography.CipherMode.ECB;
System.Security.Cryptography.ICryptoTransform DESEncrypter = AES.CreateEncryptor();
byte[] Buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(input);
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length));
return encrypted;
}
catch (Exception ex)
{
}
return encrypted;
}
public string AES_Decrypt(string input, string pass)
{
System.Security.Cryptography.RijndaelManaged AES = new System.Security.Cryptography.RijndaelManaged();
System.Security.Cryptography.MD5CryptoServiceProvider Hash_AES = new System.Security.Cryptography.MD5CryptoServiceProvider();
string decrypted = "";
try
{
byte[] hash = new byte[32];
byte[] temp = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass));
Array.Copy(temp, 0, hash, 0, 16);
Array.Copy(temp, 0, hash, 15, 16);
AES.Key = hash;
AES.Mode = System.Security.Cryptography.CipherMode.ECB;
System.Security.Cryptography.ICryptoTransform DESDecrypter = AES.CreateDecryptor();
byte[] Buffer = Convert.FromBase64String(input);
decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length));
return decrypted;
}
catch (Exception ex)
{
}
return decrypted;
}RSA:
Code
public string RSA_Encrypt(string Input)
{
System.Security.Cryptography.CspParameters cp = new System.Security.Cryptography.CspParameters();
cp.Flags = System.Security.Cryptography.CspProviderFlags.UseMachineKeyStore;
cp.KeyContainerName = "Keys";
System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider(cp);
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(Input);
byte[] encrypted = RSA.Encrypt(buffer, true);
return Convert.ToBase64String(encrypted);
}
public string RSA_Decrypt(string Input)
{
System.Security.Cryptography.CspParameters cp = new System.Security.Cryptography.CspParameters();
cp.Flags = System.Security.Cryptography.CspProviderFlags.UseMachineKeyStore;
cp.KeyContainerName = "Keys";
System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider(cp);
byte[] buffer = Convert.FromBase64String(Input);
byte[] decrypted = RSA.Decrypt(buffer, true);
return System.Text.Encoding.UTF8.GetString(decrypted);
}Enjoy!



