Using AppContext.BaseDirectory - as Assembly.Location might not be available in single-file applications.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
@@ -19,16 +18,14 @@ namespace System.Security.Cryptography
|
||||
/// <param name="keyFile">The (absolute) path to the crypto key file. On <c>null</c> the file 'crypto.key' at the executing assembly location will be used.</param>
|
||||
public CryptographyHelper(string keyFile = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyFile))
|
||||
keyFile = "crypto.key";
|
||||
|
||||
if (!Path.IsPathRooted(keyFile))
|
||||
{
|
||||
string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
keyFile = Path.Combine(dir, keyFile);
|
||||
}
|
||||
masterKeyFile = keyFile;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(masterKeyFile))
|
||||
masterKeyFile = "crypto.key";
|
||||
|
||||
if (!Path.IsPathRooted(masterKeyFile))
|
||||
masterKeyFile = Path.Combine(AppContext.BaseDirectory, masterKeyFile);
|
||||
|
||||
string pw = File.Exists(masterKeyFile) ? File.ReadAllText(masterKeyFile) : null;
|
||||
if (string.IsNullOrWhiteSpace(pw))
|
||||
File.WriteAllText(masterKeyFile, GetRandomString(64));
|
||||
|
||||
Reference in New Issue
Block a user