Skip to content

Commit

Permalink
Pushing FAES v1.1.3 to Stable
Browse files Browse the repository at this point in the history
Pushing FAES v1.1.3 to Stable
  • Loading branch information
mullak99 authored Dec 29, 2018
2 parents 699d602 + 5004d61 commit 7d1c063
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 86 deletions.
13 changes: 12 additions & 1 deletion Changelog_FAES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,20 @@
~ FAES Encryption Mode: FAESv2-CBC
~ Supported FAES Encryption Modes: Legacy, FAESv1-CBC and FAESv2-CBC

|---| 1.1.1 |---|
|---| 1.1.2 |---|

- Added GetVersion() method

~ FAES Encryption Mode: FAESv2-CBC
~ Supported FAES Encryption Modes: Legacy, FAESv1-CBC and FAESv2-CBC
~ Supported FAES Compression Modes: LegacyZIP

|---| 1.1.3 |---|

- Added FAES version to encrypted file metadata
- Added method to manually delete instanced temp paths
- Changed password hint padding character
- Fully fixed invalid character showing up in password hints

~ FAES Encryption Mode: FAESv2-CBC
~ Supported FAES Encryption Modes: Legacy, FAESv1-CBC and FAESv2-CBC
14 changes: 11 additions & 3 deletions FAES/AES/MetaDataFAES.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal class MetaDataFAES
{
protected byte[] _passwordHint;
protected byte[] _encryptionTimestamp;
protected byte[] _encryptionVersion;

/// <summary>
/// Converts various pieces of MetaData into easy-to-manage method calls
Expand All @@ -17,6 +18,7 @@ public MetaDataFAES(string passwordHint)
{
_passwordHint = ConvertStringToBytes(passwordHint);
_encryptionTimestamp = BitConverter.GetBytes((int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds);
_encryptionVersion = ConvertStringToBytes(FileAES_Utilities.GetVersion(), 16);
}

/// <summary>
Expand All @@ -27,6 +29,7 @@ public MetaDataFAES(byte[] metaData)
{
_passwordHint = metaData.Take(64).ToArray();
_encryptionTimestamp = metaData.Skip(64).Take(4).ToArray();
_encryptionVersion = metaData.Skip(68).Take(16).ToArray();
}

/// <summary>
Expand All @@ -36,7 +39,11 @@ public MetaDataFAES(byte[] metaData)
public string getPasswordHint()
{
if (_passwordHint != null)
return Encoding.UTF8.GetString(_passwordHint).Replace("¬", "");
{
string converted = Encoding.UTF8.GetString(_passwordHint).Replace("¬", "");
if (converted.Contains("�")) converted = converted.Replace("�", "");
return converted;
}
else
return null;
}
Expand All @@ -62,6 +69,7 @@ public byte[] getMetaData()
byte[] formedMetaData = new byte[256];
Buffer.BlockCopy(_passwordHint, 0, formedMetaData, 0, _passwordHint.Length);
Buffer.BlockCopy(_encryptionTimestamp, 0, formedMetaData, 64, _encryptionTimestamp.Length);
Buffer.BlockCopy(_encryptionVersion, 0, formedMetaData, 68, _encryptionVersion.Length);

return formedMetaData;
}
Expand All @@ -73,12 +81,12 @@ public byte[] getMetaData()
/// <param name="maxLength">Max length of the string</param>
/// <param name="paddingChar">Character used to pad the string if required</param>
/// <returns></returns>
private byte[] ConvertStringToBytes(string value, int maxLength = 64, char paddingChar = '¬')
private byte[] ConvertStringToBytes(string value, int maxLength = 64)
{
if (value.Length > maxLength)
return Encoding.UTF8.GetBytes(value.Substring(0, maxLength));
else
return Encoding.UTF8.GetBytes(value.PadRight(maxLength, paddingChar));
return Encoding.UTF8.GetBytes(value.PadRight(maxLength, '\0'));
}
}
}
70 changes: 67 additions & 3 deletions FAES/FAES.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand Down Expand Up @@ -56,6 +57,7 @@ public FAES_File(string filePath)
/// <param name="password">Password to encrypt/decrypt the file</param>
/// <param name="success">Output of if the action was successful</param>
/// <param name="passwordHint">Hint for the password (only used for encryption)</param>
[Obsolete("This method of creating a FAES_File is deprecated. Please use the alternative method and specify FAES_Encrypt/FAES_Decrypt")]
public FAES_File(string filePath, string password, ref bool success, string passwordHint = null)
{
if (File.Exists(filePath) || Directory.Exists(filePath))
Expand Down Expand Up @@ -88,6 +90,7 @@ private void Initialise()
/// Runs the appropriate action (Encrypt/Decrypt)
/// </summary>
/// <param name="success">Output of if the action was successful</param>
[Obsolete("This method of automatically encrypting/decrypting a FAES_File is deprecated. Please use FAES_Encrypt/FAES_Decrypt.")]
public void Run(ref bool success)
{
if (!String.IsNullOrEmpty(_password))
Expand Down Expand Up @@ -116,6 +119,7 @@ public void Run(ref bool success)
/// Sets the Password used to encrypt/decrypt the current FAES File
/// </summary>
/// <param name="password">Chosen Password</param>
[Obsolete("This method of automatically encrypting/decrypting a FAES_File is deprecated. Please use FAES_Encrypt/FAES_Decrypt.")]
public void setPassword(string password)
{
_password = password;
Expand Down Expand Up @@ -269,10 +273,33 @@ public FileAES_Encrypt(FAES_File file, string password, string passwordHint = nu
_file = file;
_password = password;
_passwordHint = passwordHint;


}
else throw new Exception("This filetype cannot be encrypted!");
}

/// <summary>
/// Creates a new temp path and adds it to the instancedTempFolders list
/// </summary>
private void CreateTempPath()
{
Directory.CreateDirectory(Path.Combine(tempPath));
FileAES_Utilities._instancedTempFolders.Add(tempPath);
}

/// <summary>
/// Deletes the temp path after use and removes it from the instancedTempFolders list
/// </summary>
private void DeleteTempPath()
{
if (Directory.Exists(tempPath))
{
Directory.Delete(tempPath, true);
FileAES_Utilities._instancedTempFolders.Remove(tempPath);
}
}

/// <summary>
/// Encrypts current file
/// </summary>
Expand All @@ -288,7 +315,7 @@ public bool encryptFile()
{
if (_file.isFile())
{
if (!Directory.Exists(Path.Combine(tempPath))) Directory.CreateDirectory(Path.Combine(tempPath));
if (!Directory.Exists(Path.Combine(tempPath))) CreateTempPath();

using (ZipArchive zip = ZipFile.Open(Path.Combine(tempPath, _file.getFileName()) + ".faeszip", ZipArchiveMode.Create))
{
Expand All @@ -299,6 +326,7 @@ public bool encryptFile()
else
{
tempFolderName = FileAES_IntUtilities.genRandomTempFolder(_file.getFileName().Substring(0, _file.getFileName().Length - Path.GetExtension(_file.getFileName()).Length));
FileAES_Utilities._instancedTempFolders.Add(tempFolderName);
if (Directory.Exists(Path.Combine(tempPath, tempFolderName))) Directory.Delete(Path.Combine(tempPath, tempFolderName), true);
FileAES_IntUtilities.DirectoryCopy(_file.getPath(), Path.Combine(tempPath, tempFolderName, _file.getFileName()), true);
ZipFile.CreateFromDirectory(Path.Combine(tempPath, tempFolderName), Path.Combine(tempPath, _file.getFileName()) + ".faeszip");
Expand Down Expand Up @@ -349,7 +377,7 @@ public bool encryptFile()
if (File.Exists(fileToDelete))
File.Delete(fileToDelete);

if (Directory.Exists(tempPath)) Directory.Delete(tempPath, true);
DeleteTempPath();
}
return success;
}
Expand All @@ -373,10 +401,24 @@ public FileAES_Decrypt(FAES_File file, string password)
{
_file = file;
_password = password;

FileAES_Utilities._instancedTempFolders.Add(tempPath);
}
else throw new Exception("This filetype cannot be decrypted!");
}

/// <summary>
/// Deletes the temp path after use and removes it from the instancedTempFolders list
/// </summary>
private void DeleteTempPath()
{
if (Directory.Exists(tempPath))
{
Directory.Delete(tempPath, true);
FileAES_Utilities._instancedTempFolders.Remove(tempPath);
}
}

/// <summary>
/// Decrypts current file
/// </summary>
Expand Down Expand Up @@ -413,7 +455,7 @@ public bool decryptFile()
}
}

if (Directory.Exists(tempPath)) Directory.Delete(tempPath, true);
DeleteTempPath();
if (File.Exists(Path.ChangeExtension(_file.getPath(), "faeszip"))) File.Delete(Path.ChangeExtension(_file.getPath(), "faeszip"));

return success;
Expand All @@ -434,6 +476,8 @@ public string getPasswordHint()

public class FileAES_Utilities
{
internal static List<string> _instancedTempFolders = new List<string>();

/// <summary>
/// Gets if the chosen file is encryptable
/// </summary>
Expand Down Expand Up @@ -464,6 +508,15 @@ public static void PurgeTempFolder()
if (Directory.Exists(Path.Combine(Path.GetTempPath(), "FileAES"))) Directory.Delete(Path.Combine(Path.GetTempPath(), "FileAES"), true);
}

public static void PurgeInstancedTempFolders()
{
foreach (string iTempFolder in _instancedTempFolders)
{
if (Directory.Exists(iTempFolder)) Directory.Delete(iTempFolder, true);
}
_instancedTempFolders.Clear();
}

/// <summary>
/// Gets the FAES Version
/// </summary>
Expand Down Expand Up @@ -494,7 +547,18 @@ public static string GetPasswordHint(string filePath)
/// </summary>
/// <param name="filePath">Encrypted File</param>
/// <returns>Encryption Timestamp (UNIX UTC)</returns>
[Obsolete("This method includes a typo, please switch to 'GetEncryptionTimeStamp' before updating to FAES 1.2.0.")]
public static int GetEncrpytionTimeStamp(string filePath)
{
return GetEncryptionTimeStamp(filePath);
}

/// <summary>
/// Gets the Encryption Timestamp (UNIX UTC) of when the chosen file was encrypted
/// </summary>
/// <param name="filePath">Encrypted File</param>
/// <returns>Encryption Timestamp (UNIX UTC)</returns>
public static int GetEncryptionTimeStamp(string filePath)
{
int encryptTimestamp = -1;

Expand Down
10 changes: 7 additions & 3 deletions FAES/FAES.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

<PropertyGroup>
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
<Version>1.1.2</Version>
<AssemblyVersion>1.1.2.0</AssemblyVersion>
<PackageReleaseNotes>- Added GetVersion() method</PackageReleaseNotes>
<Version>1.1.3</Version>
<AssemblyVersion>1.1.3.0</AssemblyVersion>
<PackageReleaseNotes>- Added FAES version to encrypted file metadata
- Added method to manually delete instanced temp paths
- Changed password hint padding character
- Fully fixed invalid character showing up in password hints</PackageReleaseNotes>
<Authors>mullak99</Authors>
<Description>C# Library to encrypt/decrypt files using AES. With extra features.</Description>
<FileVersion>1.1.3.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions FileAES-Legacy/FileAES-Decrypt.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 37 additions & 6 deletions FileAES-Legacy/FileAES-Decrypt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,25 @@ private void decryptButton_Click(object sender, EventArgs e)
if (Core.isDecryptFileValid(_fileToDecrypt) && !_inProgress) backgroundDecrypt.RunWorkerAsync();
else if (_inProgress) setNoteLabel("Decryption already in progress.", 1);
else setNoteLabel("Decryption Failed. Try again later.", 1);

runtime_Tick(sender, e);
}
}

private void setNoteLabel(string note, int severity)
{
if (severity == 1) noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Warning: " + note; }));
else if (severity == 2) noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Important: " + note; }));
else if (severity == 3) noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Error: " + note; }));
else noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Note: " + note; }));
if (note.Contains("ERROR:"))
{
note = note.Replace("ERROR:", "Error:");
noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = note; }));
}
else
{
if (severity == 1) noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Warning: " + note; }));
else if (severity == 2) noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Important: " + note; }));
else if (severity == 3) noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Error: " + note; }));
else noteLabel.Invoke(new MethodInvoker(delegate { this.noteLabel.Text = "Note: " + note; }));
}
}

private void doDecrypt()
Expand Down Expand Up @@ -94,8 +104,22 @@ private void backgroundDecrypt_Complete(object sender, RunWorkerCompletedEventAr

private void runtime_Tick(object sender, EventArgs e)
{
if (Core.isDecryptFileValid(_fileToDecrypt) && passwordInput.Text.Length > 3 && !_inProgress) decryptButton.Enabled = true;
else decryptButton.Enabled = false;
if (_inProgress)
{
decryptButton.Enabled = false;
passwordInput.Enabled = false;
}
else if (Core.isDecryptFileValid(_fileToDecrypt) && passwordInput.Text.Length > 3 && !_inProgress)
{
decryptButton.Enabled = true;
passwordInput.Enabled = true;

}
else
{
decryptButton.Enabled = false;
passwordInput.Enabled = true;
}
}

private void passwordBox_Focus(object sender, EventArgs e)
Expand All @@ -119,6 +143,8 @@ protected override void OnFormClosing(FormClosingEventArgs e)
{
if (File.Exists(Path.Combine(Directory.GetParent(_fileToDecrypt).FullName, fileName.Text.Substring(0, fileName.Text.Length - Path.GetExtension(fileName.Text).Length) + ".faeszip")))
File.Delete(Path.Combine(Directory.GetParent(_fileToDecrypt).FullName, fileName.Text.Substring(0, fileName.Text.Length - Path.GetExtension(fileName.Text).Length) + ".faeszip"));

FileAES_Utilities.PurgeInstancedTempFolders();
}
catch (Exception)
{
Expand All @@ -136,6 +162,11 @@ private void versionLabel_Click(object sender, EventArgs e)
update.Show();
}

private void noteLabel_MouseHover(object sender, EventArgs e)
{
slowToolTip.SetToolTip(noteLabel, noteLabel.Text);
}

protected override bool ProcessDialogKey(Keys keyData)
{
if (Form.ModifierKeys == Keys.None && keyData == Keys.Escape)
Expand Down
Loading

0 comments on commit 7d1c063

Please sign in to comment.