Skip to content

Commit

Permalink
Merge pull request eesast#206 from DreamEnderKing/dev
Browse files Browse the repository at this point in the history
Change the encryptor from rsa to aes.
  • Loading branch information
ONLOX authored Apr 11, 2024
2 parents 7cbaa28 + 917575f commit 1652525
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions installer/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,30 @@ public static MauiApp CreateMauiApp()
// read SecretID & SecretKey from filePath for debug
var filePath = Debugger.IsAttached ? "D:\\Secret.csv" : Path.Combine(AppContext.BaseDirectory, "Secret.csv");
var lines = File.ReadAllLines(filePath);
if (lines.Length > 0)
if (lines.Length >= 4)
{
var param = new CspParameters();
param.KeyContainerName = lines[0];
using (var rsa = new RSACryptoServiceProvider(param))
lines = lines.Select(s => s.Trim().Trim('\r', '\n')).ToArray();
using (Aes aes = Aes.Create())
{
var b1 = Convert.FromBase64String(lines[1]);
var b2 = Convert.FromBase64String(lines[2]);
SecretID = Encoding.ASCII.GetString(rsa.Decrypt(b1, false));
SecretKey = Encoding.ASCII.GetString(rsa.Decrypt(b2, false));
aes.Key = Convert.FromBase64String(lines[0]);
aes.IV = Convert.FromBase64String(lines[1]);
var decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
using (MemoryStream memory = new MemoryStream(Convert.FromBase64String(lines[2])))
{
using (CryptoStream crypto = new CryptoStream(memory, decryptor, CryptoStreamMode.Read))
{
using (StreamReader reader = new StreamReader(crypto, Encoding.ASCII))
SecretID = reader.ReadToEnd();
}
}
using (MemoryStream memory = new MemoryStream(Convert.FromBase64String(lines[3])))
{
using (CryptoStream crypto = new CryptoStream(memory, decryptor, CryptoStreamMode.Read))
{
using (StreamReader reader = new StreamReader(crypto, Encoding.ASCII))
SecretKey = reader.ReadToEnd();
}
}
}
}

Expand Down

0 comments on commit 1652525

Please sign in to comment.