От: | Streamer1 | ||
Дата: | 06.06.06 22:10 | ||
Оценка: | 24 (5) | ||
#Имя: | FAQ.dotnet.RSACrypto.keygen |
private static string publicKey = @"<RSAKeyValue><Modulus>s2nF3YcI+jaRcdtfWbVmkWbN2own5Jb4XOLbvwZYMqTLZA40rn2CVRj//66N2La+ay8Zg0Hjil7hXZGkC0ujTYecdGhPnyAH7TC3A7Ksz+kg2z32N5vgk+ZpVIiU+9wi83fsD5Ojk8QuTlYiQpyxWI66d5h6I7BoWmhnmeM2YPk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
private static string privateKey = @"<RSAKeyValue><Modulus>s2nF3YcI+jaRcdtfWbVmkWbN2own5Jb4XOLbvwZYMqTLZA40rn2CVRj//66N2La+ay8Zg0Hjil7hXZGkC0ujTYecdGhPnyAH7TC3A7Ksz+kg2z32N5vgk+ZpVIiU+9wi83fsD5Ojk8QuTlYiQpyxWI66d5h6I7BoWmhnmeM2YPk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
Product=Super Puper Mega Software System
LicenseType=FULL
MegaAddress=http://www.supermegasoft.medved.preved.net
UserName=Медвед
Product=Super Puper Mega Software System
LicenseType=FULL
MegaAddress=http://www.supermegasoft.medved.preved.net
UserName=Медвед
SuperPuperSignature=DKGEA8FVCEC3CHGIENFRCDFQDOFTE9GRB9AECIENAIEKGHCYABA8ECEUB5GSE1AQBOCCFRBZENAODYBQEUCBCYCEACE0DGFJE7BZG4DOEYEMF2D3G2B3BPB0BKG4C7EMGHDHB8D1FOF8FMF0BDBYEHENGJE4GED8CIGMCNFPE0ETFFCUCPA6BPBPF6CADKFCERAGF0AEEIB5AGGBA8CHGHESGJBVGYDJDJEJFIBEAAGLGQA5AICCE0AVDRFWCOGE
{CIEXADGACIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAC7
ACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB
9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJA
AB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB
7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AA
BCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5
AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAA
B8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACP
AAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AA
CJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5
AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB
7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEA
AB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AAC
FAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5A
ACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB
6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIA
AB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACL
AAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AA
CEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9
AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAA
B5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AABCIAAB5AAB7AAB6AACJAAB5AACPAAB9AACFAAB8AACEAAB5AACLAAB7AAB9AABTAAB7A
AB9AAB7AAB8AAB3AACOAAB3AACFAAB7AACAAAB3AACPAAB3AAB3AAB8AABSAAAKAA}
Product=Super Puper Mega Software System
LicenseType=FULL
MegaAddress=http://www.supermegasoft.medved.preved.net
UserName=Медвед
SuperPuperSignature=DKGEA8FVCEC3CHGIENFRCDFQDOFTE9GRB9AECIENAIEKGHCYABA8ECEUB5GSE1AQBOCCFRBZENAODYBQEUCBCYCEACE0DGFJE7BZG4DOEYEMF2D3G2B3BPB0BKG4C7EMGHDHB8D1FOF8FMF0BDBYEHENGJE4GED8CIGMCNFPE0ETFFCUCPA6BPBPF6CADKFCERAGF0AEEIB5AGGBA8CHGHESGJBVGYDJDJEJFIBEAAGLGQA5AICCE0AVDRFWCOGE
private static string alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// заворачивание:
public static string EncodeLicenseKey(string licenseKey, bool split)
{
return ("{" + Encode(Encoding.Unicode.GetBytes(licenseKey), split) + "}");
}
public static string Encode(byte[] bytes, bool split)
{
StringBuilder builder = new StringBuilder();
if (bytes != null)
{
for (int i = 0; i < bytes.Length; i++)
{
if ((split && ((i % 0x20) == 0)) && (i > 0))
{
builder.Append("\r\n");
}
builder.Append(alphabet[bytes[i] / alphabet.Length]);
builder.Append(alphabet[bytes[i] % alphabet.Length]);
}
}
return builder.ToString();
}
// разворачивание:
public static string DecodeLicenseKey(string text)
{
StringBuilder builder = new StringBuilder();
bool flag = false;
for (int i = 0; i < text.Length; i++)
{
if (!flag && (text[i] == '{'))
flag = true;
else
{
if (text[i] == '}')
break;
if (alphabet.IndexOf(text[i]) != -1)
builder.Append(text[i]);
}
}
return Encoding.Unicode.GetString(Decode(builder.ToString()));
}
public static byte[] Decode(string text)
{
if (text == null)
{
text = string.Empty;
}
byte[] buffer = new byte[text.Length / 2];
for (int i = 0; i < (buffer.Length * 2); i += 2)
{
buffer[i / 2] = (byte)((alphabet.IndexOf(text[i]) * alphabet.Length) + alphabet.IndexOf(text[i + 1]));
}
return buffer;
}
public static bool CheckLicenseSign(string licenseText, string signText, string publicKey)
{
byte[] buffer1 = Decode(signText);
RSACryptoServiceProvider provider = new RSACryptoServiceProvider(0x400);
provider.FromXmlString(publicKey);
byte[] buffer2 = Encoding.Unicode.GetBytes(licenseText);
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] buffer3 = sha.ComputeHash(buffer2);
RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(provider);
deformatter.SetHashAlgorithm("SHA1");
return deformatter.VerifySignature(buffer3, buffer1);
}
private void buttonSign_Click(object sender, EventArgs e)
{
// ....<skip>...
licenseText = GetSuperLicenseText(collection);
byte[] buffer2 = Encoding.Unicode.GetBytes(licenseText);
RSACryptoServiceProvider myprov = new RSACryptoServiceProvider(0x400);
myprov.FromXmlString(privateKey);
SHA1 sha1 = new SHA1CryptoServiceProvider();
byte[] buffer3 = sha1.ComputeHash(buffer2);
RSAPKCS1SignatureFormatter formatter1 = new RSAPKCS1SignatureFormatter(myprov);
formatter1.SetHashAlgorithm("SHA1");
byte[] buffer1 = formatter1.CreateSignature(buffer3);
string mysign = Encode(buffer1, false); // получили подпись
licenseLines.Add("SuperPuperSignature=" + mysign); // добавили строчку с подписью
// ...<skip>
}