[C#]Encryptions Thread(RSA,XOR,RC4,Etc) - Mr. Anderson - Nov 14, 2010
All these encryptions are ported off the ones posted in Prototypes thread.
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!
* - xhtmlphp™ - Nov 14, 2010
You should put it into a class library so people can download and import the .dll and use functions such as rc4(string data, string key) and provide snippets.
Good release but an encryption library would be helpful.
* - Noxin - Nov 14, 2010
Could you please provide a link to Prototypes thread, as that is not his username, thank you.
* - Mr. Anderson - Nov 14, 2010
https://hackforums.net/showthread.php?tid=668060&highlight=encryption
|