Skip to content

Commit fff97b3

Browse files
authored
Update some code and functionality
- renew algorithm for generate password - add some description in about form - cleaning in account entities
1 parent 7a5a886 commit fff97b3

10 files changed

+331
-143
lines changed

Properties/Resources.Designer.cs

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Resources.resx

+7-4
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,18 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<data name="Header" xml:space="preserve">
121-
<value>FFFFFFFFFFFFFFC5</value>
122-
<comment>Header for QPDB</comment>
123-
</data>
124120
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
125121
<data name="icons8_eye_32" type="System.Resources.ResXFileRef, System.Windows.Forms">
126122
<value>..\Resources\icons8-eye-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
127123
</data>
128124
<data name="icons8_eye_hide_32" type="System.Resources.ResXFileRef, System.Windows.Forms">
129125
<value>..\Resources\icons8-eye_hide-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
130126
</data>
127+
<data name="Header" xml:space="preserve">
128+
<value>FFFFFFFFFFFFFFC5</value>
129+
<comment>Header for QPDB</comment>
130+
</data>
131+
<data name="icons8-github-32" type="System.Resources.ResXFileRef, System.Windows.Forms">
132+
<value>..\Resources\icons8-github-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
133+
</data>
131134
</root>

QPass.csproj

+12
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
<Compile Include="Source\Entities\Account.cs" />
9898
<Compile Include="Source\Entities\FileManager.cs" />
9999
<Compile Include="Source\Entities\Groups.cs" />
100+
<Compile Include="Source\Forms\AboutForm.cs">
101+
<SubType>Form</SubType>
102+
</Compile>
103+
<Compile Include="Source\Forms\AboutForm.Designer.cs">
104+
<DependentUpon>AboutForm.cs</DependentUpon>
105+
</Compile>
100106
<Compile Include="Source\Forms\AccountForm.cs">
101107
<SubType>Form</SubType>
102108
</Compile>
@@ -132,6 +138,9 @@
132138
<SubType>Designer</SubType>
133139
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
134140
</EmbeddedResource>
141+
<EmbeddedResource Include="Source\Forms\AboutForm.resx">
142+
<DependentUpon>AboutForm.cs</DependentUpon>
143+
</EmbeddedResource>
135144
<EmbeddedResource Include="Source\Forms\AccountForm.resx">
136145
<DependentUpon>AccountForm.cs</DependentUpon>
137146
</EmbeddedResource>
@@ -179,5 +188,8 @@
179188
<ItemGroup>
180189
<None Include="Resources\icons8-eye_hide-32.png" />
181190
</ItemGroup>
191+
<ItemGroup>
192+
<None Include="Resources\icons8-github-32.png" />
193+
</ItemGroup>
182194
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
183195
</Project>

Resources/icons8-github-32.png

589 Bytes
Loading

Source/Crypto/QPDBCrypto.cs

+40
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,42 @@ public QPDBCrypto()
1414

1515
}
1616

17+
#region Private
18+
19+
private void Check(byte[] key, byte[] iv)
20+
{
21+
if (key == null)
22+
{
23+
throw new System.Exception("Key can't null.");
24+
}
25+
if (key.Length < 32)
26+
{
27+
throw new System.Exception("Key not 256 bit.");
28+
}
29+
if (iv == null)
30+
{
31+
throw new System.Exception("IV can't null.");
32+
}
33+
if (iv.Length < 32)
34+
{
35+
throw new System.Exception("IV not 256 bit.");
36+
}
37+
}
38+
39+
#endregion Private
40+
1741
#region Public
1842

43+
/// <summary>
44+
/// encrypt data using rijndael
45+
/// </summary>
46+
/// <param name="data"></param>
47+
/// <param name="key"></param>
48+
/// <param name="iv"></param>
49+
/// <returns></returns>
1950
public byte[] Encrypt(byte[] data, byte[] key, byte[] iv)
2051
{
52+
this.Check(key, iv);
2153
//Set up
2254
//AesEngine engine = new AesEngine();
2355
RijndaelEngine engine = new RijndaelEngine(256);
@@ -36,8 +68,16 @@ public byte[] Encrypt(byte[] data, byte[] key, byte[] iv)
3668
return outputBytes;
3769
}
3870

71+
/// <summary>
72+
/// decrypt data using rijdael
73+
/// </summary>
74+
/// <param name="data"></param>
75+
/// <param name="key"></param>
76+
/// <param name="iv"></param>
77+
/// <returns></returns>
3978
public byte[] Decrypt(byte[] data, byte[] key, byte[] iv)
4079
{
80+
this.Check(key, iv);
4181
//Set up
4282
//AesEngine engine = new AesEngine();
4383
RijndaelEngine engine = new RijndaelEngine(256);

Source/Entities/Account.cs

+16-114
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Org.BouncyCastle.Crypto.Modes;
77
using Org.BouncyCastle.Crypto.Paddings;
88
using Org.BouncyCastle.Crypto.Parameters;
9+
using QPass.Crypto;
910

1011
namespace QPass.Entities
1112
{
@@ -146,41 +147,26 @@ private byte[] CreateKey(byte[] master_password)
146147
return result;
147148
}
148149

150+
/// <summary>
151+
/// encrypt data
152+
/// </summary>
153+
/// <param name="data"></param>
154+
/// <returns></returns>
149155
private byte[] Encrypt(byte[] data)
150156
{
151-
//Set up
152-
//AesEngine engine = new AesEngine();
153-
RijndaelEngine engine = new RijndaelEngine(256);
154-
CbcBlockCipher blockCipher = new CbcBlockCipher(engine); //CBC
155-
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher, new Pkcs7Padding()); //Default scheme is PKCS5/PKCS7
156-
KeyParameter keyParam = new KeyParameter(this._Key.SubByte(0, 32));
157-
ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, this._IV, 0, 32);
158-
159-
// Encrypt
160-
cipher.Init(true, keyParamWithIV);
161-
byte[] outputBytes = new byte[cipher.GetOutputSize(data.Length)];
162-
int length = cipher.ProcessBytes(data, outputBytes, 0);
163-
cipher.DoFinal(outputBytes, length); //Do the final block
164-
165-
//string encryptedInput = outputBytes.EncodeBase16();//Convert.ToBase64String(outputBytes);
166-
return outputBytes;
157+
QPDBCrypto cipher = new QPDBCrypto();
158+
return cipher.Encrypt(data, this._Key, this._IV);
167159
}
168160

161+
/// <summary>
162+
/// decrypt data
163+
/// </summary>
164+
/// <param name="data"></param>
165+
/// <returns></returns>
169166
private byte[] Decrypt(byte[] data)
170167
{
171-
//Set up
172-
//AesEngine engine = new AesEngine();
173-
RijndaelEngine engine = new RijndaelEngine(256);
174-
CbcBlockCipher blockCipher = new CbcBlockCipher(engine); //CBC
175-
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher, new Pkcs7Padding()); //Default scheme is PKCS5/PKCS7
176-
KeyParameter keyParam = new KeyParameter(this._Key.SubByte(0, 32));
177-
ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, this._IV, 0, 32);
178-
179-
cipher.Init(false, keyParamWithIV);
180-
byte[] outputBytes = new byte[cipher.GetOutputSize(data.Length)];
181-
int length = cipher.ProcessBytes(data, outputBytes, 0);
182-
cipher.DoFinal(outputBytes, length); //Do the final block
183-
return outputBytes;
168+
QPDBCrypto cipher = new QPDBCrypto();
169+
return cipher.Decrypt(data, this._Key, this._IV);
184170
}
185171

186172
#endregion Private
@@ -546,91 +532,7 @@ public string GetModifiedDate(bool str = true)
546532
#endregion Public
547533

548534
#region Method
549-
550-
///// <summary>
551-
///// Encrypt account data.
552-
///// </summary>
553-
///// <param name="username">Encrypt username.</param>
554-
///// <param name="password">Encrypt password.</param>
555-
///// <param name="note">Encrypt note.</param>
556-
///// <returns></returns>
557-
//[Obsolete]
558-
//private bool Encrypt(bool username = true, bool password = true, bool note = true)
559-
//{
560-
// if (this._IV == null || this._IV.Length != this._IVLength)
561-
// {
562-
// return false;
563-
// }
564-
565-
// if (this._Encrypted == true)
566-
// {
567-
// return false;
568-
// }
569-
570-
// Rabbit cipher = new Rabbit();
571-
// cipher.SetKey(this._Salt.SubByte(0, 16));
572-
// cipher.SetIV(this._IV.SubByte(0, 8));
573-
574-
// if (username == true)
575-
// {
576-
// this._Username = cipher.Encrypt(this._Username).EncodeBase16();
577-
// }
578-
579-
// if (password == true)
580-
// {
581-
// this._Password = cipher.Encrypt(this._Password).EncodeBase16();
582-
// }
583-
584-
// if (note == true)
585-
// {
586-
// this._Note = cipher.Encrypt(this._Note).EncodeBase16();
587-
// }
588-
589-
// return true;
590-
//}
591-
592-
///// <summary>
593-
///// Decrypt account data.
594-
///// </summary>
595-
///// <param name="username">Decrypt username.</param>
596-
///// <param name="password">Decrypt password.</param>
597-
///// <param name="note">Decrypt note.</param>
598-
///// <returns></returns>
599-
//[Obsolete]
600-
//private bool Decrypt(bool username = true, bool password = true, bool note = true)
601-
//{
602-
// if (this._IV == null || this._IV.Length != this._IVLength)
603-
// {
604-
// return false;
605-
// }
606-
607-
// if (this._Encrypted == false)
608-
// {
609-
// return false;
610-
// }
611-
612-
// Rabbit cipher = new Rabbit();
613-
// cipher.SetKey(this._Salt.SubByte(0, 16));
614-
// cipher.SetIV(this._IV.SubByte(0, 8));
615-
616-
// if (username == true)
617-
// {
618-
// this._Username = cipher.Decrypt(this._Username.DecodeBase16()).GetString();
619-
// }
620-
621-
// if (password == true)
622-
// {
623-
// this._Password = cipher.Decrypt(this._Password.DecodeBase16()).GetString();
624-
// }
625-
626-
// if (note == true)
627-
// {
628-
// this._Note = cipher.Decrypt(this._Note.DecodeBase16()).GetString();
629-
// }
630-
631-
// return true;
632-
//}
633-
535+
634536
/// <summary>
635537
/// Encrypt account data.
636538
/// </summary>

Source/Forms/AboutForm.Designer.cs

+41-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Forms/AboutForm.cs

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Windows.Forms;
1+
using System.Diagnostics;
2+
using System.Runtime.InteropServices;
3+
using System.Windows.Forms;
24

35
namespace QPass.Forms
46
{
@@ -8,5 +10,36 @@ public AboutForm()
810
{
911
InitializeComponent();
1012
}
13+
14+
private void GithubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
15+
{
16+
string url = "https://github.com/Shiroechi/QPass-Password-Manager";
17+
try
18+
{
19+
Process.Start(url);
20+
}
21+
catch
22+
{
23+
// hack because of this: https://github.com/dotnet/corefx/issues/10361
24+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
25+
{
26+
url = url.Replace("&", "^&");
27+
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
28+
}
29+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
30+
{
31+
Process.Start("xdg-open", url);
32+
}
33+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
34+
{
35+
Process.Start("open", url);
36+
}
37+
else
38+
{
39+
return;
40+
//throw;
41+
}
42+
}
43+
}
1144
}
1245
}

0 commit comments

Comments
 (0)