Skip to content

Commit 4b434a5

Browse files
committed
fixed stuff hopefully
1 parent 7bf130b commit 4b434a5

26 files changed

+661
-299
lines changed

Encryption App/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.IO;
7+
using System.Security.Cryptography;
8+
9+
namespace Encryption_App
10+
{
11+
class Encryptor
12+
{
13+
14+
private static readonly string cryptFileEnding;
15+
16+
public byte[] SymEncrypt(byte[] data, byte[] pwd)
17+
{
18+
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
19+
using (AesManaged AES = new AesManaged())
20+
{
21+
AES.KeySize = 256;
22+
AES.BlockSize = 128;
23+
24+
var key = new Rfc2898DeriveBytes(pwd, saltBytes, 1000);
25+
AES.Key = key.GetBytes(AES.KeySize / 8);
26+
AES.IV = key.GetBytes(AES.BlockSize / 8);
27+
28+
AES.Mode = CipherMode.CBC;
29+
byte[] bArray = new byte[16];
30+
using (var ms = new MemoryStream())
31+
{
32+
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
33+
{
34+
using (var bw = new BinaryWriter(cs))
35+
{
36+
bw.Write(data, 0, data.Length);
37+
}
38+
}
39+
return ms.ToArray();
40+
}
41+
}
42+
}
43+
44+
public byte[] SymDecrypt(byte[] data, byte[] pwd)
45+
{
46+
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
47+
using (AesManaged AES = new AesManaged())
48+
{
49+
AES.KeySize = 256;
50+
AES.BlockSize = 128;
51+
AES.Padding = PaddingMode.PKCS7;
52+
53+
var key = new Rfc2898DeriveBytes(pwd, saltBytes, 1000);
54+
AES.Key = key.GetBytes(AES.KeySize / 8);
55+
AES.IV = key.GetBytes(AES.BlockSize / 8);
56+
57+
AES.Mode = CipherMode.CBC;
58+
byte[] bArray = new byte[16];
59+
using (var ms = new MemoryStream())
60+
{
61+
using (var cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Read))
62+
{
63+
cs.CopyTo(ms);
64+
}
65+
return ms.ToArray();
66+
}
67+
}
68+
}
69+
70+
/*public void SymEncrypt(byte[] bArray, byte[] pwdBytes)
71+
{
72+
byte[] encryptedBytes = null;
73+
74+
// Set your salt here, change it to meet your flavor:
75+
// The salt bytes must be at least 8 bytes.
76+
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
77+
78+
using (MemoryStream ms = new MemoryStream())
79+
{
80+
using (AesManaged AES = new AesManaged())
81+
{
82+
AES.KeySize = 256;
83+
AES.BlockSize = 128;
84+
85+
var key = new Rfc2898DeriveBytes(pwdBytes, saltBytes, 1000);
86+
AES.Key = key.GetBytes(AES.KeySize / 8);
87+
AES.IV = key.GetBytes(AES.BlockSize / 8);
88+
89+
AES.Mode = CipherMode.CBC;
90+
91+
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
92+
{
93+
cs.Write(bArray, 0, bArray.Length);
94+
cs.Close();
95+
}
96+
encryptedBytes = ms.ToArray();
97+
}
98+
}
99+
100+
101+
}*/
102+
103+
}
104+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{701B9935-7BF8-4BA2-861A-7764761C1318}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>Encryption_App</RootNamespace>
10+
<AssemblyName>Encryption App</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Xml" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="System.Net.Http" />
46+
<Reference Include="System.Xaml">
47+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
48+
</Reference>
49+
<Reference Include="WindowsBase" />
50+
<Reference Include="PresentationCore" />
51+
<Reference Include="PresentationFramework" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<ApplicationDefinition Include="UI\App.xaml">
55+
<Generator>MSBuild:Compile</Generator>
56+
<SubType>Designer</SubType>
57+
</ApplicationDefinition>
58+
<Page Include="UI\MainWindow.xaml">
59+
<Generator>MSBuild:Compile</Generator>
60+
<SubType>Designer</SubType>
61+
</Page>
62+
<Compile Include="UI\App.xaml.cs">
63+
<DependentUpon>App.xaml</DependentUpon>
64+
<SubType>Code</SubType>
65+
</Compile>
66+
<Compile Include="Backend\Encryptor.cs" />
67+
<Compile Include="UI\MainWindow.xaml.cs">
68+
<DependentUpon>MainWindow.xaml</DependentUpon>
69+
<SubType>Code</SubType>
70+
</Compile>
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Compile Include="Properties\AssemblyInfo.cs">
74+
<SubType>Code</SubType>
75+
</Compile>
76+
<Compile Include="Properties\Resources.Designer.cs">
77+
<AutoGen>True</AutoGen>
78+
<DesignTime>True</DesignTime>
79+
<DependentUpon>Resources.resx</DependentUpon>
80+
</Compile>
81+
<Compile Include="Properties\Settings.Designer.cs">
82+
<AutoGen>True</AutoGen>
83+
<DependentUpon>Settings.settings</DependentUpon>
84+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
85+
</Compile>
86+
<EmbeddedResource Include="Properties\Resources.resx">
87+
<Generator>ResXFileCodeGenerator</Generator>
88+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
89+
</EmbeddedResource>
90+
<None Include="Properties\Settings.settings">
91+
<Generator>SettingsSingleFileGenerator</Generator>
92+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
93+
</None>
94+
</ItemGroup>
95+
<ItemGroup>
96+
<None Include="App.config" />
97+
</ItemGroup>
98+
<ItemGroup />
99+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100+
</Project>

Encryption App/Program.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.IO;
3+
using System.Security.Cryptography;
4+
5+
namespace Aes_Example
6+
{
7+
class AesExample
8+
{
9+
public static void Main()
10+
{
11+
try
12+
{
13+
// Create a new instance of the AesManaged
14+
// class. This generates a new key and initialization
15+
// vector (IV).
16+
using (AesManaged myAes = new AesManaged())
17+
{
18+
19+
AES_Encrypt("file.txt", "file.crypt", new byte[10]);
20+
AES_Decrypt("file.crypt", "file.dcryptd", new byte[10]);
21+
}
22+
23+
}
24+
catch (Exception e)
25+
{
26+
Console.WriteLine("Error: {0}", e.Message);
27+
}
28+
Console.Read();
29+
}
30+
private static void AES_Encrypt(string iF, string oF, byte[] passwordBytes)
31+
{
32+
33+
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
34+
35+
using (var outFile = File.Create(oF))
36+
{
37+
38+
using (var AES = new RijndaelManaged())
39+
{
40+
41+
AES.KeySize = 256;
42+
AES.BlockSize = 128;
43+
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 100000);
44+
AES.Key = key.GetBytes(AES.KeySize / 8);
45+
AES.IV = key.GetBytes(AES.BlockSize / 8);
46+
AES.Padding = PaddingMode.PKCS7;
47+
AES.Mode = CipherMode.CBC;
48+
49+
using (var cs = new CryptoStream(outFile, AES.CreateEncryptor(), CryptoStreamMode.Write))
50+
{
51+
52+
using (var inFile = File.OpenRead(iF))
53+
{
54+
55+
using (var br = new BinaryReader(inFile))
56+
{
57+
58+
sbyte data;
59+
while ((data = (sbyte)inFile.ReadByte()) != -1)
60+
cs.WriteByte((byte)data);
61+
62+
}
63+
}
64+
}
65+
}
66+
}
67+
}
68+
69+
private static void AES_Decrypt(string iF, string oF, byte[] passwordBytes)
70+
{
71+
72+
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
73+
74+
using (var inFile = File.OpenRead(iF))
75+
{
76+
77+
using (var AES = new RijndaelManaged())
78+
{
79+
80+
AES.KeySize = 256;
81+
AES.BlockSize = 128;
82+
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 100000);
83+
AES.Key = key.GetBytes(AES.KeySize / 8);
84+
AES.IV = key.GetBytes(AES.BlockSize / 8);
85+
AES.Padding = PaddingMode.PKCS7;
86+
AES.Mode = CipherMode.CBC;
87+
88+
using (var cs = new CryptoStream(inFile, AES.CreateDecryptor(), CryptoStreamMode.Read))
89+
{
90+
91+
using (var outFile = File.Create(oF))
92+
{
93+
94+
sbyte data;
95+
while ((data = (sbyte)cs.ReadByte()) != -1)
96+
outFile.WriteByte((byte)data);
97+
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("Encryption App")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("Encryption App")]
15+
[assembly: AssemblyCopyright("Copyright © 2018")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)