Skip to content

Commit

Permalink
Added ChangeSalt argument function
Browse files Browse the repository at this point in the history
  • Loading branch information
hellzerg committed Feb 2, 2022
1 parent 8e0c238 commit b2229b6
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 84 deletions.
37 changes: 37 additions & 0 deletions Lain/CryLain.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;

namespace Lain
{
Expand All @@ -21,6 +24,15 @@ internal static string HashKey(string key)
}
}

private static string HashKeyCustomSalt(string key, string customSalt)
{
using (SHA256 sha256 = SHA256.Create())
{
byte[] hashed = sha256.ComputeHash(Encoding.UTF8.GetBytes(key + customSalt));
return Convert.ToBase64String(hashed);
}
}

internal static SecureString ToSecureString(string key)
{
SecureString ss = new SecureString();
Expand Down Expand Up @@ -80,6 +92,31 @@ internal string Decrypt(string key, string data)
return decrypted;
}

internal static bool ChangeSalt(string toSalt, string oldKey)
{
string _newKey = CryLain.HashKeyCustomSalt(oldKey, toSalt);

if (string.IsNullOrEmpty(oldKey) || string.IsNullOrEmpty(_newKey)) return false;

try
{
File.WriteAllText(Required.LainSerial, _newKey);
return true;
}
catch (Exception err)
{
MessageBox.Show(err.Message, "Lain", MessageBoxButtons.OK, MessageBoxIcon.Information);
Environment.Exit(0);
return false;
}
finally
{
oldKey = string.Empty;
_newKey = string.Empty;
toSalt = string.Empty;
}
}

private string Protect(string plainText, byte[] Key, byte[] IV)
{
if (plainText == null || plainText.Length <= 0)
Expand Down
61 changes: 31 additions & 30 deletions Lain/Forms/MainForm.Designer.cs

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

7 changes: 1 addition & 6 deletions Lain/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,7 @@ private void CheckForUpdate()
File.Move(tempFile, appFile);

// BYPASS SINGLE-INSTANCE MECHANISM
if (Program.MUTEX != null)
{
Program.MUTEX.ReleaseMutex();
Program.MUTEX.Dispose();
Program.MUTEX = null;
}
Program.RestartLain();

Application.Restart();
}
Expand Down
10 changes: 5 additions & 5 deletions Lain/Forms/NewForm.Designer.cs

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

60 changes: 30 additions & 30 deletions Lain/Forms/OptionsForm.Designer.cs

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

Loading

0 comments on commit b2229b6

Please sign in to comment.