Hello, im currently working on a small project to create a program that allows a user to input text, select an encryption alogrithm and cipher his text. I found this DES class and was wondering would be to comment on it in order for to understand what is going on
P.S: programming language C#
Code:
class DES
{
public string DES_Encrypt(string originalString, string pass)
{
byte[] bytes = ASCIIEncoding.ASCII.GetBytes(pass);
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
StreamWriter writer = new StreamWriter(cryptoStream);
writer.Write(originalString);
writer.Flush();
cryptoStream.FlushFinalBlock();
writer.Flush();
return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
}
public string DES_Decrypt(string cryptedString, string pass)
{
byte[] bytes = ASCIIEncoding.ASCII.GetBytes(pass);
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(cryptedString));
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Read);
StreamReader reader = new StreamReader(cryptoStream);
return reader.ReadToEnd();
}
}