在注册表中存储许可证信息的最安全方法是什么 - C#
What is most secure way to store the license information in registry - c#
我使用 win-form C# 制作了我的应用程序的试用版,为此我在 HKEY_CURRENT_USER.
中存储许可证信息,例如安装日期、上次使用日期和黑名单用户变量
现在担心用户可以轻松访问此注册表信息或修改其值。如果他们这样做,那么跟踪应用程序可以在到期后重复使用。
有人,请建议我保护此注册表信息的最佳方法。
- 如何加密注册表信息?
- 如何阻止对用户的修改访问,同时只有我的应用程序有权修改注册表(因为我的应用程序修改了注册表中最后使用的变量。
- 我的 c# 应用程序可以使用任何其他替代方法来保护此许可证信息和相同的信息(类似于注册表项,我的应用程序可以在其中读取和修改其 属性 数据值)
一段我的代码
private void firstTimeAppOpen()
{
RegistryKey regkey = Registry.CurrentUser;
regkey = regkey.CreateSubKey(globalPath); //path
DateTime dt = DateTime.Now;
string Date = dt.ToShortDateString(); // get only date not time
regkey.SetValue("Install", Date); //Value Name,Value Data
regkey.SetValue("Use", Date); //Value Name,Value Data
}
// put next use day in registry
regkey.SetValue("Use", DateTime.Now); //Value Name,Value Data
下面的屏幕截图显示我的所有数据(如安装日期、上次使用日期)都是可见的,并且可以在用户找到时进行修改。
简而言之,这种解决方案总是容易受到攻击。但是,您可以让它变得不方便。
考虑根据这些属性计算哈希值并将其存储在注册表中。如果用户试图修改这些值,那么存储的哈希值将不再与预期值匹配,您就会知道注册表已被篡改。
聪明的用户可以绕过这个系统,但它会阻止随意篡改。
这是您可能如何计算哈希值的示例:
var installDate = new DateTime(2016, 12, 28); // replace with registry value
var useDate = new DateTime(2017, 01, 31); // replace with registry value
var inputs = installDate.ToString("yyyy-MM-dd") + "," + useDate.ToString("yyyy-MM-dd");
using (var sha = new System.Security.Cryptography.SHA256CryptoServiceProvider())
{
var hash = sha.ComputeHash(Encoding.ASCII.GetBytes(inputs));
}
我在这个问题上找不到任何帮助。正如所有其他文章或 post 所暗示的那样,不可能保护客户机器上的数据,因为他们可以完全访问自己的机器。
但是,我们仍然可以将它们与我们的数据混淆,因为在上面的屏幕截图中可以看到我的注册表数据像日期一样对所有人公开可见。加密和解密日期也是如此。首先,我加密日期并将其存储在注册表中,然后在需要的地方再次检索我的注册表数据并解密以供进一步使用。如果用户篡改了加密数据,我们将在解密时获知。
关于加密和解密的示例代码。
public string EncryptData(string data)
{
if (data == null)
throw new ArgumentNullException("data");
//encrypt data
var encryptdata = Encoding.Unicode.GetBytes(data);
byte[] encrypted = ProtectedData.Protect(encryptdata, null, DataProtectionScope.CurrentUser);
//return as base64 string
return Convert.ToBase64String(encrypted);
}
public string DecryptData(string cipher)
{
if (cipher == null) throw new ArgumentNullException("cipher");
//parse base64 string
byte[] data = Convert.FromBase64String(cipher);
//decrypt data
byte[] decrypted = ProtectedData.Unprotect(data, null, DataProtectionScope.CurrentUser);
return Encoding.Unicode.GetString(decrypted);
}
private void firstTimeAppOpen()
{
RegistryKey regkey = Registry.CurrentUser;
regkey = regkey.CreateSubKey(globalPath); //path
DateTime dt = DateTime.Now;
string Date = dt.ToShortDateString(); // get only date not time
string getDate = EncryptData(Date);
regkey.SetValue("Install", getDate); //Value Name,Value Data
regkey.SetValue("Use", getDate); //Value Name,Value Data
}
加密后的注册表
我使用 win-form C# 制作了我的应用程序的试用版,为此我在 HKEY_CURRENT_USER.
中存储许可证信息,例如安装日期、上次使用日期和黑名单用户变量现在担心用户可以轻松访问此注册表信息或修改其值。如果他们这样做,那么跟踪应用程序可以在到期后重复使用。
有人,请建议我保护此注册表信息的最佳方法。
- 如何加密注册表信息?
- 如何阻止对用户的修改访问,同时只有我的应用程序有权修改注册表(因为我的应用程序修改了注册表中最后使用的变量。
- 我的 c# 应用程序可以使用任何其他替代方法来保护此许可证信息和相同的信息(类似于注册表项,我的应用程序可以在其中读取和修改其 属性 数据值)
一段我的代码
private void firstTimeAppOpen()
{
RegistryKey regkey = Registry.CurrentUser;
regkey = regkey.CreateSubKey(globalPath); //path
DateTime dt = DateTime.Now;
string Date = dt.ToShortDateString(); // get only date not time
regkey.SetValue("Install", Date); //Value Name,Value Data
regkey.SetValue("Use", Date); //Value Name,Value Data
}
// put next use day in registry
regkey.SetValue("Use", DateTime.Now); //Value Name,Value Data
下面的屏幕截图显示我的所有数据(如安装日期、上次使用日期)都是可见的,并且可以在用户找到时进行修改。
简而言之,这种解决方案总是容易受到攻击。但是,您可以让它变得不方便。
考虑根据这些属性计算哈希值并将其存储在注册表中。如果用户试图修改这些值,那么存储的哈希值将不再与预期值匹配,您就会知道注册表已被篡改。
聪明的用户可以绕过这个系统,但它会阻止随意篡改。
这是您可能如何计算哈希值的示例:
var installDate = new DateTime(2016, 12, 28); // replace with registry value
var useDate = new DateTime(2017, 01, 31); // replace with registry value
var inputs = installDate.ToString("yyyy-MM-dd") + "," + useDate.ToString("yyyy-MM-dd");
using (var sha = new System.Security.Cryptography.SHA256CryptoServiceProvider())
{
var hash = sha.ComputeHash(Encoding.ASCII.GetBytes(inputs));
}
我在这个问题上找不到任何帮助。正如所有其他文章或 post 所暗示的那样,不可能保护客户机器上的数据,因为他们可以完全访问自己的机器。 但是,我们仍然可以将它们与我们的数据混淆,因为在上面的屏幕截图中可以看到我的注册表数据像日期一样对所有人公开可见。加密和解密日期也是如此。首先,我加密日期并将其存储在注册表中,然后在需要的地方再次检索我的注册表数据并解密以供进一步使用。如果用户篡改了加密数据,我们将在解密时获知。
关于加密和解密的示例代码。
public string EncryptData(string data)
{
if (data == null)
throw new ArgumentNullException("data");
//encrypt data
var encryptdata = Encoding.Unicode.GetBytes(data);
byte[] encrypted = ProtectedData.Protect(encryptdata, null, DataProtectionScope.CurrentUser);
//return as base64 string
return Convert.ToBase64String(encrypted);
}
public string DecryptData(string cipher)
{
if (cipher == null) throw new ArgumentNullException("cipher");
//parse base64 string
byte[] data = Convert.FromBase64String(cipher);
//decrypt data
byte[] decrypted = ProtectedData.Unprotect(data, null, DataProtectionScope.CurrentUser);
return Encoding.Unicode.GetString(decrypted);
}
private void firstTimeAppOpen()
{
RegistryKey regkey = Registry.CurrentUser;
regkey = regkey.CreateSubKey(globalPath); //path
DateTime dt = DateTime.Now;
string Date = dt.ToShortDateString(); // get only date not time
string getDate = EncryptData(Date);
regkey.SetValue("Install", getDate); //Value Name,Value Data
regkey.SetValue("Use", getDate); //Value Name,Value Data
}
加密后的注册表