File Crypter
Downloads:
Executable
Source Code (C#)
Installer
Description:
File Crypter is a file encryption/decryption application, it handles both text and binary files, and features a key generator, its primary purpose is to offer an additional level of security when moving files around on the internet, or securely encrypting files without having to rely on commercial third party software, its also a nice way to get around gmail’s and many other email services refusal to allow you to email executables.
It should be noted that although the files are encrypted using 256 bit Rijndael, the keys (or pass phrases) generated by the application are fairly weak, though the code exist in the application to used the encryption libraries native key generator, its currently commented out, and produces something a bit more human readable. The source is available to any that would care to make the change.
Screen Shot(s):
Notable Code:
Below is listed both the methods used to create the keys for the application, (this points out the flaws, the padding for example being a ‘ ‘ series of white spaces, thoughts on improving this, would be to takes the key phrase passed by the user, turning that into an int, and using that as a random seed to generate a repeatable, but seemingly random string to pad with.
The other code listed is a method of writing the data to a file, and a common example I found that isn’t binary safe, and should be avoided (regardless if published on the MSDN)
public string GenerateKey()
{
CryptoService.GenerateKey();
return ASCIIEncoding.ASCII.GetString(CryptoService.Key);
}
private byte[] PrepKeyIV(string Key)
{
int blockSize = CryptoService.BlockSize;
// key sizes are in bits
if (Key.Length * 8 > blockSize)
{
//truncate key to block size since password and IV are the same
return ASCIIEncoding.ASCII.GetBytes(Key.Remove((blockSize / 8)));
}
else if (Key.Length * 8 < blockSize)
{
//pad key to block size since password and IV are the same
return ASCIIEncoding.ASCII.GetBytes(Key.PadRight(blockSize / 8, ' '));
}
else
{
//if the key is a proper key, return it untouched.
return ASCIIEncoding.ASCII.GetBytes(Key);
}
public bool Decrypting(string sInputFilename, string sOutputFilename, string sKey)
{
byte[] bytKey = PrepKeyIV(sKey);
// set the private key
CryptoService.Key = bytKey;
CryptoService.IV = bytKey;
// create a MemoryStream with the input
FileStream fsInput = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read);
FileStream fsDecrypted = new FileStream(sOutputFilename, FileMode.Create, FileAccess.Write);
// create a Decryptor from the Provider Service instance
ICryptoTransform decrypto = CryptoService.CreateDecryptor();
// create Crypto Stream that transforms a stream using the decryption
CryptoStream cryptostreamDecr = new CryptoStream(fsDecrypted, decrypto, CryptoStreamMode.Write);
try
{
//write the contents of the decrypted file.
/*
* This method is not binary safe and will muck up the encoding
StreamWriter fsDecrypted = new StreamWriter(sOutputFilename);
fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd());
fsDecrypted.Flush();
fsDecrypted.Close();
*/
byte[] bytearrayinput = new byte[fsInput.Length];
fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
cryptostreamDecr.Write(bytearrayinput, 0, bytearrayinput.Length);
return true;
}
catch (Exception err)
{
//handle error usually triggered from a bad key phrase.
return false;
}
finally
{
cryptostreamDecr.Close();
fsInput.Close();
fsDecrypted.Close();
}
