使用 RSA 密钥保护许可证密钥
已经很晚了,我很累,而且可能相当密集......
我已经编写了一个需要保护的应用程序,因此它只能在我为其生成密钥的计算机上运行。 我现在正在做的是获取 BIOS 序列号并从中生成哈希值,然后使用 XML RSA 私钥对其进行加密。然后我对 XML 进行签名以确保它不被篡改。 我试图打包公钥来解密和验证签名,但是每次我尝试以与生成签名的用户不同的用户身份执行代码时,我都会遇到签名失败的情况。
我的大部分代码都是根据我找到的示例代码修改的,因为我对 RSA 加密并不像我希望的那样熟悉。下面是我正在使用的代码以及我认为我需要使用的代码才能使其正常工作...
任何反馈将不胜感激,因为我此时已经迷失了方向 我正在使用的原始代码是这样的,只要启动该程序的用户与最初签署文档的用户相同,该代码就可以正常工作...
CspParameters cspParams = new CspParameters();
cspParams.KeyContainerName = "XML_DSIG_RSA_KEY";
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
// Create a new RSA signing key and save it in the container.
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams)
{
PersistKeyInCsp = true,
};
该代码是我认为我应该做的,但它无法验证无论我做什么,无论它是同一个用户还是不同的用户......
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();
//Load the private key from xml file
XmlDocument xmlPrivateKey = new XmlDocument();
xmlPrivateKey.Load("KeyPriv.xml");
rsaKey.FromXmlString(xmlPrivateKey.InnerXml);
我相信这与密钥容器名称有关(这里是一个真正的傻瓜,请原谅我)我很确定这是该行既导致它在第一种情况下工作,又阻止它在第二种情况下工作......
cspParams.KeyContainerName = "XML_DSIG_RSA_KEY";
有没有办法让我在生成应用程序许可证时使用私钥对 XML 进行签名/加密,然后将公钥放在应用程序目录中并使用它来验证/解密代码?如果我能让签名部分正常工作,我可以放弃加密部分。我用它作为备份来混淆我正在输入的许可证代码的来源。
这些有道理吗? 我是个十足的傻瓜吗?
感谢任何人都可以在这方面给我的任何帮助..
it's late, I'm tired, and probably being quite dense....
I have written an application that I need to secure so it will only run on machines that I generate a key for.
What I am doing for now is getting the BIOS serial number and generating a hash from that, I then am encrypting it using a XML RSA private key. I then sign the XML to ensure that it is not tampered with.
I am trying to package the public key to decrypt and verify the signature with, but every time I try to execute the code as a different user than the one that generated the signature I get a failure on the signature.
Most of my code is modified from sample code I have found since I am not as familiar with RSA encryption as I would like to be. Below is the code I was using and the code I thought I needed to use to get this working right...
Any feedback would be greatly appreciated as I am quite lost at this point
the original code I was working with was this, this code works fine as long as the user launching the program is the same one that signed the document originally...
CspParameters cspParams = new CspParameters();
cspParams.KeyContainerName = "XML_DSIG_RSA_KEY";
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
// Create a new RSA signing key and save it in the container.
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams)
{
PersistKeyInCsp = true,
};
This code is what I believe I should be doing but it's failing to verify the signature no matter what I do, regardless if it's the same user or a different one...
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();
//Load the private key from xml file
XmlDocument xmlPrivateKey = new XmlDocument();
xmlPrivateKey.Load("KeyPriv.xml");
rsaKey.FromXmlString(xmlPrivateKey.InnerXml);
I believe this to have something to do with the key container name (Being a real dumbass here please excuse me) I am quite certain that this is the line that is both causing it to work in the first case and preventing it from working in the second case....
cspParams.KeyContainerName = "XML_DSIG_RSA_KEY";
Is there a way for me to sign/encrypt the XML with a private key when the application license is generated and then drop the public key in the app directory and use that to verify/decrypt the code? I can drop the encryption part if I can get the signature part working right. I was using it as a backup to obfuscate the origin of the license code I am keying from.
Does any of this make sense?
Am I a total dunce?
Thanks for any help anyone can give me in this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用此方法使用存储在 xml 文件中的私钥对 xml 文档进行签名,然后将其作为资源嵌入到应用程序 .dll 中。我认为您可能在访问密钥库的权限方面遇到困难,这也会造成将代码传输到其他服务器等的麻烦。
以下是获取私钥作为嵌入式资源并签署文档的代码:
(Sign是该方法所在类的名称,Licensing.Private.Private.xml是默认命名空间+资源文件夹+文件名的组合)
使用以下代码生成private.xml和public.xml键。显然,要确保 private.xml 文件的安全。
I used this method to sign xml documents using a private key stored in an xml file that I then embedded into the application .dll as a resource. I think you may be struggling with permissions accessing the keystore, and this would also create hassles transferring the code to other servers etc.
Here is the code to get the private key as an embedded resource and sign the document:
(Sign is the name of the class this method is located in, Licensing.Private.Private.xml is a combination of the default namespace + folder + filename of the resource)
Use the following code the generate the private.xml and public.xml keys. Keep the private.xml file secure, obviously.
我猜,问题是不同的用户无权访问为第一个用户存储的密钥(请注意:我不是密码学专家)。
Guess, the problem is that different users don't have access to the key that is stored for the 1st user (Please note: I am not a cryptography expert).