using System.Security.Cryptography;
public class StandardEncryptor
public static void Main()
string unencryptedString = "prouser;propassword;tesg;2022-05-09 12:00:00";
string password = "17983436";
System.Console.WriteLine("Unencrypted String: " + unencryptedString);
System.Console.WriteLine("Password: " + password);
encryptedString = StandardEncryptor.Encrypt(unencryptedString, password);
System.Console.WriteLine("Encrypted String: " + encryptedString);
decryptedString = StandardEncryptor.Decrypt(encryptedString, password);
System.Console.WriteLine("Decrypted String: " + decryptedString);
public static string Encrypt(string message, string password)
byte[] messageBytes = ASCIIEncoding.ASCII.GetBytes(message);
byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(password);
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Mode = CipherMode.ECB;
ICryptoTransform transform = provider.CreateEncryptor(passwordBytes, passwordBytes);
CryptoStreamMode mode = CryptoStreamMode.Write;
MemoryStream memStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memStream, transform, mode);
cryptoStream.Write(messageBytes, 0, messageBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] encryptedMessageBytes = new byte[memStream.Length];
memStream.Read(encryptedMessageBytes, 0, encryptedMessageBytes.Length);
string encryptedMessage = ToHexString(encryptedMessageBytes);
public static string Decrypt(string encryptedMessage, string password)
byte[] encryptedMessageBytes = StringToByteArray(encryptedMessage);
byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(password);
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Mode = CipherMode.ECB;
ICryptoTransform transform = provider.CreateDecryptor(passwordBytes, passwordBytes);
CryptoStreamMode mode = CryptoStreamMode.Write;
MemoryStream memStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memStream, transform, mode);
cryptoStream.Write(encryptedMessageBytes, 0, encryptedMessageBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] decryptedMessageBytes = new byte[memStream.Length];
memStream.Read(decryptedMessageBytes, 0, decryptedMessageBytes.Length);
string message = ASCIIEncoding.ASCII.GetString(decryptedMessageBytes);
public static string ToHexString(byte[] bytes)
string hexString = string.Empty;
StringBuilder str = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
str.Append(bytes[i].ToString("X2"));
hexString = str.ToString();
public static byte[] StringToByteArray(string hex) {
return Enumerable.Range(0, hex.Length)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))