| 订阅 | 在线投稿
分享
 
 
 

简述.Net下的应用程序授权实战步骤

2008-12-13 08:23:28  编辑来源:互联网  宽屏版  评论

本文为【简述.Net下的应用程序授权实战步骤】的汉字拼音对照版显示拼音

kanlekanlexiamiannapianCrackbierenyingyongchengxudewenzhangyouganjianshu.Netxiadeyingyongchengxushouquanzijishijicaozuolebadechudexinde zheliyuanliabeijingashenmedoubujieshaolexiaowangrenshengyijingzaitadeBLOGshangdouxiedexiangdangqingchuleyoushenmebuxijiebumingbaidekeyiqukanyuanwentuijianxiandagaikanxiayuanwenxiankanwoxiamiandebuzhouranhouzaihuitouquyanjiuyuanwendexijieyouyuwozijixiedeshilishiyongzaigongsiyixiangmuzhongyuandaimajiubufang便bianfangchulaileheihei

diyibushengchengyizugongyaohesiyaogongyaoyongyunifabuchengxusiyaoshuyuzhucemashengchengview plaincopy to clipboardprint?

using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())

{

// gongyao

string pubkey = rsa.ToXmlString(false);

// siyao

string prikey = rsa.ToXmlString(true);

//ruguoshiwebFormjiuResponse.Write(pubkey + <br/> + prikey); xia

//ruguoshiwinFormjiuMessageBox.Show("gongyao:" + pubkey + "\r\nsiyao:" + prikey); xia

}

using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())

{

// gongyao

string pubkey = rsa.ToXmlString(false);

// siyao

string prikey = rsa.ToXmlString(true);

//ruguoshiwebFormjiuResponse.Write(pubkey + <br/> + prikey); xia

//ruguoshiwinFormjiuMessageBox.Show("gongyao:" + pubkey + "\r\nsiyao:" + prikey); xia

}dierbuqudejiqiyingjianbianmawoxuanyongCUPdebianhaoview plaincopy to clipboardprint?

/// <summary>

/// huoquCPUbianhao

/// </summary>

/// <returns></returns>

public string GetCpuId()

{

ManagementClass mc = new ManagementClass("Win32_Processor");

ManagementObjectCollection moc = mc.GetInstances();

String strCpuID = null;

foreach (ManagementObject mo in moc)

{

strCpuID = mo.Properties["ProcessorId"].Value.ToString();

break;

}

return strCpuID;

}

/// <summary>

/// huoquCPUbianhao

/// </summary>

/// <returns></returns>

public string GetCpuId()

{

ManagementClass mc = new ManagementClass("Win32_Processor");

ManagementObjectCollection moc = mc.GetInstances();

String strCpuID = null;

foreach (ManagementObject mo in moc)

{

strCpuID = mo.Properties["ProcessorId"].Value.ToString();

break;

}

return strCpuID;

}disanbubianxiezhucemashengchengWinFormchengxu使shiyongCUPdebianhaolaishengchengzhucemadangranniyekeyiyong WebFormlaixieview plaincopy to clipboardprint?

using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())

{

rsa.FromXmlString(siyao);

// jiamiduixiang

RSAPKCS1SignatureFormatter f = new RSAPKCS1SignatureFormatter(rsa);

f.SetHashAlgorithm("SHA1");

byte[] source = System.Text.ASCIIEncoding.ASCII.GetBytes(CUPdebianhao);

SHA1Managed sha = new SHA1Managed();

byte[] result = sha.ComputeHash(source);

byte[] b = f.CreateSignature(result);

msg.Text = Convert.ToBase64String(b); //zhelijiudedaolestringxingshidezhucema

//zaijiexialainikeyibashengchengdezhucemabaocunchenglicense.licwenjianlicense.licwenjianyemeishenmetebiedegeshijiushixiangdangyubazhucemabaocundaoyigetxtwenjianzhongwufeizhegetxtwenjiandehouzhuigaichenglelicniyaogaoxingyekebaocunchengqitaduozhonggeshi

//yekeyibaocunzaizhucebiaozhonghuoshiweb.configzhongzongzhinengrangnidefabudeyingyongchengxunengdudedaojiuxing

}

using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())

{

rsa.FromXmlString(siyao);

// jiamiduixiang

RSAPKCS1SignatureFormatter f = new RSAPKCS1SignatureFormatter(rsa);

f.SetHashAlgorithm("SHA1");

byte[] source = System.Text.ASCIIEncoding.ASCII.GetBytes(CUPdebianhao);

SHA1Managed sha = new SHA1Managed();

byte[] result = sha.ComputeHash(source);

byte[] b = f.CreateSignature(result);

msg.Text = Convert.ToBase64String(b); //zhelijiudedaolestringxingshidezhucema

//zaijiexialainikeyibashengchengdezhucemabaocunchenglicense.licwenjianlicense.licwenjianyemeishenmetebiedegeshijiushixiangdangyubazhucemabaocundaoyigetxtwenjianzhongwufeizhegetxtwenjiandehouzhuigaichenglelicniyaogaoxingyekebaocunchengqitaduozhonggeshi

//yekeyibaocunzaizhucebiaozhonghuoshiweb.configzhongzongzhinengrangnidefabudeyingyongchengxunengdudedaojiuxing

}disibuzaifabudechengxuxiangguandifangtianjiaduizhucemayouxiaoxingdeyanzhengrutianjiazaichengxuqidongdeshihouchengxuzhixingtedingcaozuodeshihoudengdengzongzhikannidexuyaozuoyouxiaoxingdeyanzhengview plaincopy to clipboardprint?

//xiangguanzhucemahuoqudaima

//yixiadaimashifabuchengxu使shiyonggongyaoduizhucemajinxingyanzheng

using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())

{

rsa.FromXmlString(gongyao);

RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsa);

f.SetHashAlgorithm("SHA1");

byte[] key = Convert.FromBase64String(zhucema);

SHA1Managed sha = new SHA1Managed();

byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(zhucema));

if(f.VerifySignature(name,key))

msg.Text = "yanzhengchenggong"; //keyireturn true;dengfangshifanhuixiangyingdezhuangtai

else

msg.Text = "buchenggong";

}

原文
  看了“看了下面那篇“Crack别人应用程序”的文章有感,简述.Net下的应用程序授权。”,自己实际操作了把得出的心得 。这里原理啊背景啊什么都不介绍了,笑望人生已经在他的BLOG上都写的相当清楚了,有什么不细节不明白的可以去看原文。推荐先大概看下原文,现看我下面的步骤,然后再回头去研究原文的细节。由于我自己写的实例是用在公司一项目中,源代码就不方便放出来了,嘿嘿。   第一步:生成一组公钥和私钥,公钥用于你发布程序,私钥属于注册码生成。view plaincopy to clipboardprint? using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { // 公钥 string pubkey = rsa.ToXmlString(false); // 私钥 string prikey = rsa.ToXmlString(true); //如果是webForm就Response.Write(pubkey + ”<br/>” + prikey); 下 //如果是winForm就MessageBox.Show("公钥:" + pubkey + "\r\n私钥:" + prikey); 下 } using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { // 公钥 string pubkey = rsa.ToXmlString(false); // 私钥 string prikey = rsa.ToXmlString(true); //如果是webForm就Response.Write(pubkey + ”<br/>” + prikey); 下 //如果是winForm就MessageBox.Show("公钥:" + pubkey + "\r\n私钥:" + prikey); 下 }  第二步:取得机器硬件编码。我选用CUP的编号。view plaincopy to clipboardprint? /// <summary> /// 获取CPU编号 /// </summary> /// <returns></returns> public string GetCpuId() { ManagementClass mc = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = mc.GetInstances(); String strCpuID = null; foreach (ManagementObject mo in moc) { strCpuID = mo.Properties["ProcessorId"].Value.ToString(); break; } return strCpuID; } /// <summary> /// 获取CPU编号 /// </summary> /// <returns></returns> public string GetCpuId() { ManagementClass mc = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = mc.GetInstances(); String strCpuID = null; foreach (ManagementObject mo in moc) { strCpuID = mo.Properties["ProcessorId"].Value.ToString(); break; } return strCpuID; }  第三步:编写注册码生成WinForm程序,使用CUP的编号来生成注册码,当然你也可以用 WebForm来写。view plaincopy to clipboardprint? using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(“私钥”); // 加密对象 RSAPKCS1SignatureFormatter f = new RSAPKCS1SignatureFormatter(rsa); f.SetHashAlgorithm("SHA1"); byte[] source = System.Text.ASCIIEncoding.ASCII.GetBytes(“CUP的编号”); SHA1Managed sha = new SHA1Managed(); byte[] result = sha.ComputeHash(source); byte[] b = f.CreateSignature(result); msg.Text = Convert.ToBase64String(b); //这里就得到了string形式的注册码 //再接下来你可以把生成的注册码保存成license.lic文件,license.lic文件也没什么特别的格式就是相当于把注册吗保存到一个txt文件中,无非这个txt文件的后缀改成了lic,你要高兴也可保存成其它多种格式。 //也可以保存在注册表中或是web.config中,总之能让你的发布的应用程序能读的到就行。 } using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(“私钥”); // 加密对象 RSAPKCS1SignatureFormatter f = new RSAPKCS1SignatureFormatter(rsa); f.SetHashAlgorithm("SHA1"); byte[] source = System.Text.ASCIIEncoding.ASCII.GetBytes(“CUP的编号”); SHA1Managed sha = new SHA1Managed(); byte[] result = sha.ComputeHash(source); byte[] b = f.CreateSignature(result); msg.Text = Convert.ToBase64String(b); //这里就得到了string形式的注册码 //再接下来你可以把生成的注册码保存成license.lic文件,license.lic文件也没什么特别的格式就是相当于把注册吗保存到一个txt文件中,无非这个txt文件的后缀改成了lic,你要高兴也可保存成其它多种格式。 //也可以保存在注册表中或是web.config中,总之能让你的发布的应用程序能读的到就行。 }  第四步:在发布的程序相关地方添加对注册码有效性的验证。如添加在程序启动的时候,程序执行特定操作的时候等等,总之看你的需要做有效性的验证。view plaincopy to clipboardprint? //相关注册码获取代码…… //以下代码是发布程序使用公钥对注册码进行验证 using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(“公钥”); RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsa); f.SetHashAlgorithm("SHA1"); byte[] key = Convert.FromBase64String(“注册码”); SHA1Managed sha = new SHA1Managed(); byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(“注册码”)); if(f.VerifySignature(name,key)) msg.Text = "验证成功"; //可以return true;等方式返回相应的状态 else msg.Text = "不成功"; }
󰈣󰈤
 
 
 
>>返回首页<<
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号wangchaonetcn
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有