一个用.NET做的软件,所有的程序集都通过maxtocode加壳过,不能用ildasm反汇编。
注册码生成的算法
采用RSA的数字签名算法,注册时,软件先获得硬盘序列号,用户把硬盘序列号给软件作者。
软件作者先用SHA1算法算出硬盘序列号的HASH,然后用数字签名算法利用私钥算出加密的数据,
就是注册码了。
注册码验证的算法
软件内部有一个RSA公钥,它和作者的私钥一对。软件先用SHA1算法算出硬盘序列号的HASH值,
然后使用这个公钥的数字签名验证算法验证这个签名的合法性如果合法,软件注册成功,否则失败。
算法如下:
注册码生成算法:
生成的就是采用Base64编码的注册码
注册验证算法:
注册码生成的算法
采用RSA的数字签名算法,注册时,软件先获得硬盘序列号,用户把硬盘序列号给软件作者。
软件作者先用SHA1算法算出硬盘序列号的HASH,然后用数字签名算法利用私钥算出加密的数据,
就是注册码了。
注册码验证的算法
软件内部有一个RSA公钥,它和作者的私钥一对。软件先用SHA1算法算出硬盘序列号的HASH值,
然后使用这个公钥的数字签名验证算法验证这个签名的合法性如果合法,软件注册成功,否则失败。
算法如下:
注册码生成算法:
1public string Signature(string Source,string PrivateKey)
2 {
3
4 byte[] data = System.Text.Encoding.ASCII.GetBytes(Source);
5 byte[] Hash ;
6
7 SHA1 sha = new SHA1CryptoServiceProvider();
8 // This is one implementation of the abstract class SHA1.
9 Hash = sha.ComputeHash(data);
10
11
12 rsa.FromXmlString(PrivateKey);
13
14 RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(rsa);
15 //Set the hash algorithm to SHA1.
16 RSAFormatter.SetHashAlgorithm("SHA1");
17
18 //Create a signature for HashValue and return it.
19 byte[] SignedHash = RSAFormatter.CreateSignature(Hash);
20
21
22 string SingnedString=Convert.ToBase64String(SignedHash);
23
24 this.WritetoFile("["+DateTime.Now.ToString()+"] Code:"+Source+" Hash:"+Convert.ToBase64String(Hash)+" \r\n","Register.log",true);
25
26 this.WritetoFile("\r\nSN: "+SingnedString+"\r\n\r\n\r\n","Register.log",true);
27
28
29 return SingnedString;
30
31 }
2 {
3
4 byte[] data = System.Text.Encoding.ASCII.GetBytes(Source);
5 byte[] Hash ;
6
7 SHA1 sha = new SHA1CryptoServiceProvider();
8 // This is one implementation of the abstract class SHA1.
9 Hash = sha.ComputeHash(data);
10
11
12 rsa.FromXmlString(PrivateKey);
13
14 RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(rsa);
15 //Set the hash algorithm to SHA1.
16 RSAFormatter.SetHashAlgorithm("SHA1");
17
18 //Create a signature for HashValue and return it.
19 byte[] SignedHash = RSAFormatter.CreateSignature(Hash);
20
21
22 string SingnedString=Convert.ToBase64String(SignedHash);
23
24 this.WritetoFile("["+DateTime.Now.ToString()+"] Code:"+Source+" Hash:"+Convert.ToBase64String(Hash)+" \r\n","Register.log",true);
25
26 this.WritetoFile("\r\nSN: "+SingnedString+"\r\n\r\n\r\n","Register.log",true);
27
28
29 return SingnedString;
30
31 }
生成的就是采用Base64编码的注册码
注册验证算法:
private bool IsValideSignature(string Hash,string SingnedHash,string PublicKey)
{
bool result=false;
try
{
RSACryptoServiceProvider rsa=new RSACryptoServiceProvider();
rsa.FromXmlString(PublicKey);
RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(rsa);
RSADeformatter.SetHashAlgorithm("SHA1");
//Verify the hash and display the results to the console.
result=RSADeformatter.VerifySignature(Convert.FromBase64String(Hash), Convert.FromBase64String(SingnedHash));
}
catch
{
result=false;
}
finally
{
}
return result;
}
}
{
bool result=false;
try
{
RSACryptoServiceProvider rsa=new RSACryptoServiceProvider();
rsa.FromXmlString(PublicKey);
RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(rsa);
RSADeformatter.SetHashAlgorithm("SHA1");
//Verify the hash and display the results to the console.
result=RSADeformatter.VerifySignature(Convert.FromBase64String(Hash), Convert.FromBase64String(SingnedHash));
}
catch
{
result=false;
}
finally
{
}
return result;
}
}