使用手册
KG_GenerateRegistrationKeyFromProject 函数函数类似 KG_GenerateRegistrationKey。主要不同在于本函数将读取重要信息 (公钥,私钥,密钥长度,密钥输出方式以及加密常数) TGenKeyParam。 KG_GenerateRegistrationKeyFromProject 有一个属性为 ansi 形式, 空值将导致程序停止运行。 警告:项目文件为绝对路径文件。 返回值
定义
function KG_GenerateRegistrationKeyFromProject(ProjectFile : PChar; kg : PKeyGenParams) : dword; external 'keygen.dll' name 'KG_GenerateRegistrationKeyFromProject';
extern "C" __declspec( dllimport ) __stdcall int KG_GenerateRegistrationKeyFromProject(char* pfile, PKeyGenParams kg);
public class Enigma_KeyGen_IDE { [DllImport("keygen.dll", CallingConvention = CallingConvention.StdCall)] public static extern uint KG_GenerateRegistrationKeyFromProject(string FileName, ref TKeyGenParams kg); }
Public Declare Function KG_GenerateRegistrationKeyFromProject Lib "keygen.dll" (ByVal ProjectName As String, ByRef kg As TKeyGenParams) As Long 实例
procedure TfrmMain.bGenFPClick(Sender: TObject); var kg : TKeyGenParams; KeyBuffer : array [0..2047] of char; dwResult : dword; begin mKey.Clear; if eUserInfo.Text = '' then begin ShowMessage('User info field is empty!'); Exit; end; ZeroMemory(@kg, SizeOf(kg)); // Hyphens kg.KeyWithHyphens := cbHyphens.Checked; // Fill key buffer ZeroMemory(@KeyBuffer, SizeOf(KeyBuffer)); kg.Key := @KeyBuffer; kg.KeyLen := SizeOf(KeyBuffer); // Fill User Info kg.RegInfo := PAnsiChar(AnsiString(eUserInfo.Text)); kg.RegInfoLen := strlen(PAnsiChar(kg.RegInfo)); // Key expiration info kg.UseKeyExpiration := cbExpirationDate.Checked; kg.ExpirationYear := YearOf(DateTimePicker1.DateTime); kg.ExpirationMonth := MonthOf(DateTimePicker1.DateTime); kg.ExpirationDay := DayOf(DateTimePicker1.DateTime); // Register After date kg.UseRegisterAfter := cbRegisterAfter.Checked; if kg.UseRegisterAfter then begin kg.RegisterAfterYear := YearOf(dtpRegisterAfter.DateTime); kg.RegisterAfterMonth := MonthOf(dtpRegisterAfter.DateTime); kg.RegisterAfterDay := DayOf(dtpRegisterAfter.DateTime); end; // Register Before date kg.UseRegisterBefore := cbRegisterBefore.Checked; if kg.UseRegisterBefore then begin kg.RegisterBeforeYear := YearOf(dtpRegisterBefore.DateTime); kg.RegisterBeforeMonth := MonthOf(dtpRegisterBefore.DateTime); kg.RegisterBeforeDay := DayOf(dtpRegisterBefore.DateTime); end; // Country kg.UseCountyLimit := cbCountry.Checked; if kg.UseCountyLimit then begin kg.CountryCode := KEY_COUNTRIES[comCountries.ItemIndex].Code; end; // Executions kg.UseExecutionsLimit := cbExecutions.Checked; if kg.UseExecutionsLimit then begin kg.ExecutionsCount := StrToInt(eExecutions.Text); end; // Days kg.UseDaysLimit := cbDays.Checked; if kg.UseDaysLimit then begin kg.DaysCount := StrToInt(eDays.Text); end; // Runtime kg.UseRunTimeLimit := cbRuntime.Checked; if kg.UseRunTimeLimit then begin kg.RunTimeMinutes := StrToInt(eRuntime.Text); end; // Global time kg.UseGlobalTimeLimit := cbGlobalTime.Checked; if kg.UseGlobalTimeLimit then begin kg.GlobalTimeMinutes := StrToInt(eGlobalTime.Text); end; // Hardware ID kg.UseHardwareLocking := cbHardwareID.Checked; kg.HardwareID := PAnsiChar(AnsiString(eHardware.Text)); // Crypt Sections kg.EncryptedSections[1] := cbSection1.Checked; kg.EncryptedSections[2] := cbSection2.Checked; kg.EncryptedSections[3] := cbSection3.Checked; kg.EncryptedSections[4] := cbSection4.Checked; kg.EncryptedSections[5] := cbSection5.Checked; kg.EncryptedSections[6] := cbSection6.Checked; kg.EncryptedSections[7] := cbSection7.Checked; kg.EncryptedSections[8] := cbSection8.Checked; kg.EncryptedSections[9] := cbSection9.Checked; kg.EncryptedSections[10] := cbSection10.Checked; kg.EncryptedSections[11] := cbSection11.Checked; kg.EncryptedSections[12] := cbSection12.Checked; kg.EncryptedSections[13] := cbSection13.Checked; kg.EncryptedSections[14] := cbSection14.Checked; kg.EncryptedSections[15] := cbSection15.Checked; kg.EncryptedSections[16] := cbSection16.Checked; // Generate reg. key dwResult := KG_GenerateRegistrationKeyFromProject('default.enigma', @kg); if dwResult = EP_NO_ERROR then begin mKey.Text := String(PAnsiChar(kg.Key)); end else begin case dwResult of EP_ERROR_UNKNOWN : mKey.Text := 'EP_ERROR_UNKNOWN '; EP_ERROR_KEYBUFFEREMPTY : mKey.Text := 'EP_ERROR_KEYBUFFEREMPTY '; EP_ERROR_KEYBUFFERISLESS : mKey.Text := 'EP_ERROR_KEYBUFFERISLESS '; EP_ERROR_REGINFOEMPTY : mKey.Text := 'EP_ERROR_REGINFOEMPTY '; EP_ERROR_REGINFOTOOLARGE : mKey.Text := 'EP_ERROR_REGINFOTOOLARGE '; EP_ERROR_PRIVATEKEYISNOTSET : mKey.Text := 'EP_ERROR_PRIVATEKEYISNOTSET '; EP_ERROR_PUBLICKEYISNOTSET : mKey.Text := 'EP_ERROR_PUBLICKEYISNOTSET '; EP_ERROR_PRIVATEKEYISINVALID : mKey.Text := 'EP_ERROR_PRIVATEKEYISINVALID '; EP_ERROR_PUBLICKEYISINVALID : mKey.Text := 'EP_ERROR_PUBLICKEYISINVALID '; EP_ERROR_KEYMODEISINVALID : mKey.Text := 'EP_ERROR_KEYMODEISINVALID '; EP_ERROR_KEYBASEISINVALID : mKey.Text := 'EP_ERROR_KEYBASEISINVALID '; EP_ERROR_CURRENTDATEISINVALID : mKey.Text := 'EP_ERROR_CURRENTDATEISINVALID '; EP_ERROR_EXPIRATIONDATEISINVALID : mKey.Text := 'EP_ERROR_EXPIRATIONDATEISINVALID'; EP_ERROR_KEYISINVALID : mKey.Text := 'EP_ERROR_KEYISINVALID '; EP_ERROR_HARDWAREID : mKey.Text := 'EP_ERROR_HARDWAREID '; EP_ERROR_HARDWAREBUFFEREMPTY : mKey.Text := 'EP_ERROR_HARDWAREBUFFEREMPTY '; EP_ERROR_HARDWAREIDINVALIDFORKEY : mKey.Text := 'EP_ERROR_HARDWAREIDINVALIDFORKEY'; EP_ERROR_PROJECTFILENOTFOUND : mKey.Text := 'EP_ERROR_PROJECTFILENOTFOUND '; EP_ERROR_INVALIDPROJECTFILE : mKey.Text := 'EP_ERROR_INVALIDPROJECTFILE '; EP_ERROR_EXECUTIONSNUMBERINVALID : mKey.Text := 'EP_ERROR_EXECUTIONSNUMBERINVALID'; EP_ERROR_DAYSNUMBERINVALID : mKey.Text := 'EP_ERROR_DAYSNUMBERINVALID '; EP_ERROR_COUNTRYCODEINVALID : mKey.Text := 'EP_ERROR_COUNTRYCODEINVALID '; EP_ERROR_RUNTIMEINVALID : mKey.Text := 'EP_ERROR_RUNTIMEINVALID '; EP_ERROR_GLOBALTIMEINVALID : mKey.Text := 'EP_ERROR_GLOBALTIMEINVALID '; EP_ERROR_INSTALLBEFOREINVALID : mKey.Text := 'EP_ERROR_INSTALLBEFOREINVALID '; EP_ERROR_INSTALLAFTERINVALID : mKey.Text := 'EP_ERROR_INSTALLAFTERINVALID '; else mKey.Text := 'Unknown error'; end; end; end;
void __fastcall TfrmMain::bGenFPClick(TObject *Sender) { TKeyGenParams kg; char keybuffer[2048]; WORD wYear; WORD wDay; WORD wMonth; DWORD dwResult; mKey->Clear(); if (eUserInfo->Text == "") { ShowMessage("Registration info is empty!"); return; } // Clear params buffer memset(&kg, 0, sizeof(kg)); // Hyphens kg.KeyWithHyphens = cbHyphens->Checked; // Fill key buffer memset(&keybuffer, 0, sizeof(keybuffer)); kg.Key = (char*) keybuffer; kg.KeyLen = sizeof(keybuffer); // Fill User Info char namebuf[255]; memset(&namebuf, 0, sizeof(namebuf)); memcpy(&namebuf, eUserInfo->Text.c_str(), eUserInfo->Text.Length()); kg.RegInfo = namebuf; kg.RegInfoLen = eUserInfo->Text.Length(); // Hardware ID kg.UseHardwareLocking = cbHardware->Checked; if (kg.UseHardwareLocking) { char hdbuf[255]; memset(&hdbuf, 0, sizeof(hdbuf)); memcpy(&hdbuf, eHardware->Text.c_str(), eHardware->Text.Length()); kg.HardwareID = hdbuf; } // Key expiration info kg.UseKeyExpiration = cbExpiration->Checked; if (kg.UseKeyExpiration) { DecodeDate(dtpExpiration->DateTime, wYear, wMonth, wDay); kg.ExpirationYear = wYear; kg.ExpirationMonth = wMonth; kg.ExpirationDay = wDay; } // Register After kg.UseRegisterAfter = cbRegisterAfter->Checked; if (kg.UseRegisterAfter) { DecodeDate(dtpRegisterAfter->DateTime, wYear, wMonth, wDay); kg.RegisterAfterYear = wYear; kg.RegisterAfterMonth = wMonth; kg.RegisterAfterDay = wDay; } // Register Before kg.UseRegisterBefore = cbRegisterBefore->Checked; if (kg.UseRegisterBefore) { DecodeDate(dtpRegisterBefore->DateTime, wYear, wMonth, wDay); kg.RegisterBeforeYear = wYear; kg.RegisterBeforeMonth = wMonth; kg.RegisterBeforeDay = wDay; } // Executions kg.UseExecutionsLimit = cbExecutions->Checked; if (kg.UseExecutionsLimit) { kg.ExecutionsCount = seExecutions->Value; } // Days kg.UseDaysLimit = cbDays->Checked; if (kg.UseDaysLimit) { kg.DaysCount = seDays->Value; } // Runtime kg.UseRunTimeLimit = cbRuntime->Checked; if (kg.UseRunTimeLimit) { kg.RunTimeMinutes = seRuntime->Value; } // Global Time kg.UseGlobalTimeLimit = cbGlobalTime->Checked; if (kg.UseGlobalTimeLimit) { kg.GlobalTimeMinutes = seGlobalTime->Value; } // Country kg.UseCountyLimit = cbCountry->Checked; if (kg.UseCountyLimit) { kg.CountryCode = KEY_COUNTRIES[comCountry->ItemIndex].Code; } // Crypt Sections kg.EncryptedSections[0] = cbSection1->Checked; kg.EncryptedSections[1] = cbSection2->Checked; kg.EncryptedSections[2] = cbSection3->Checked; kg.EncryptedSections[3] = cbSection4->Checked; kg.EncryptedSections[4] = cbSection5->Checked; kg.EncryptedSections[5] = cbSection6->Checked; kg.EncryptedSections[6] = cbSection7->Checked; kg.EncryptedSections[7] = cbSection8->Checked; kg.EncryptedSections[8] = cbSection9->Checked; kg.EncryptedSections[9] = cbSection10->Checked; kg.EncryptedSections[10] = cbSection11->Checked; kg.EncryptedSections[11] = cbSection12->Checked; kg.EncryptedSections[12] = cbSection13->Checked; kg.EncryptedSections[13] = cbSection14->Checked; kg.EncryptedSections[14] = cbSection15->Checked; kg.EncryptedSections[15] = cbSection16->Checked; dwResult = KG_GenerateRegistrationKeyFromProject("default.enigma", &kg); if (dwResult == EP_NO_ERROR) { mKey->Text = (AnsiString)kg.Key; } else { switch (dwResult) { case EP_ERROR_UNKNOWN: mKey->Text = "EP_ERROR_UNKNOWN"; break; case EP_ERROR_KEYBUFFEREMPTY: mKey->Text = "EP_ERROR_KEYBUFFEREMPTY"; break; case EP_ERROR_KEYBUFFERISLESS: mKey->Text = "EP_ERROR_KEYBUFFERISLESS"; break; case EP_ERROR_REGINFOEMPTY: mKey->Text = "EP_ERROR_REGINFOEMPTY"; break; case EP_ERROR_REGINFOTOOLARGE: mKey->Text = "EP_ERROR_REGINFOTOOLARGE"; break; case EP_ERROR_PRIVATEKEYISNOTSET: mKey->Text = "EP_ERROR_PRIVATEKEYISNOTSET"; break; case EP_ERROR_PUBLICKEYISNOTSET: mKey->Text = "EP_ERROR_PUBLICKEYISNOTSET"; break; case EP_ERROR_PRIVATEKEYISINVALID: mKey->Text = "EP_ERROR_PRIVATEKEYISINVALID"; break; case EP_ERROR_PUBLICKEYISINVALID: mKey->Text = "EP_ERROR_PUBLICKEYISINVALID"; break; case EP_ERROR_KEYMODEISINVALID: mKey->Text = "EP_ERROR_KEYMODEISINVALID"; break; case EP_ERROR_KEYBASEISINVALID: mKey->Text = "EP_ERROR_KEYBASEISINVALID"; break; case EP_ERROR_CURRENTDATEISINVALID: mKey->Text = "EP_ERROR_CURRENTDATEISINVALID"; break; case EP_ERROR_EXPIRATIONDATEISINVALID: mKey->Text = "EP_ERROR_EXPIRATIONDATEISINVALID"; break; case EP_ERROR_KEYISINVALID: mKey->Text = "EP_ERROR_KEYISINVALID"; break; case EP_ERROR_HARDWAREID: mKey->Text = "EP_ERROR_HARDWAREID"; break; case EP_ERROR_HARDWAREBUFFEREMPTY: mKey->Text = "EP_ERROR_HARDWAREBUFFEREMPTY"; break; case EP_ERROR_HARDWAREIDINVALIDFORKEY: mKey->Text = "EP_ERROR_HARDWAREIDINVALIDFORKEY"; break; case EP_ERROR_PROJECTFILENOTFOUND: mKey->Text = "EP_ERROR_PROJECTFILENOTFOUND"; break; case EP_ERROR_INVALIDPROJECTFILE: mKey->Text = "EP_ERROR_INVALIDPROJECTFILE"; break; case EP_ERROR_EXECUTIONSNUMBERINVALID: mKey->Text = "EP_ERROR_EXECUTIONSNUMBERINVALID"; break; case EP_ERROR_DAYSNUMBERINVALID: mKey->Text = "EP_ERROR_DAYSNUMBERINVALID"; break; case EP_ERROR_COUNTRYCODEINVALID: mKey->Text = "EP_ERROR_COUNTRYCODEINVALID"; break; case EP_ERROR_RUNTIMEINVALID: mKey->Text = "EP_ERROR_RUNTIMEINVALID"; break; case EP_ERROR_GLOBALTIMEINVALID: mKey->Text = "EP_ERROR_GLOBALTIMEINVALID"; break; case EP_ERROR_INSTALLBEFOREINVALID: mKey->Text = "EP_ERROR_INSTALLBEFOREINVALID"; break; case EP_ERROR_INSTALLAFTERINVALID: mKey->Text = "EP_ERROR_INSTALLAFTERINVALID"; break; default: mKey->Text = "Unknown error"; break; } } }
void CKeygenDlg::OnBnClickedButtongenfp() { // TODO: Add your control notification handler code here // TODO: Add your control notification handler code here TKeyGenParams kp; char keybuffer[2048]; char tmp[255]; char username[255]; char hardwareid[255]; SYSTEMTIME lpDate; DWORD dwResult; // Clear params buffer memset(&kp, 0, sizeof(kp)); // Clear key buffer memset(&keybuffer, 0, sizeof(keybuffer)); kp.Key = (char*) keybuffer; kp.KeyLen = sizeof(keybuffer); // Fill User Info memset(&username, 0, sizeof(username)); GetDlgItemText(IDC_EDITNAME, (char*)&username, sizeof(username)); kp.RegInfo = (char*)&username; kp.RegInfoLen = strlen(kp.RegInfo); // Key expiration info if (IsDlgButtonChecked(IDC_CHECKEXPIRATION) != 0) { kp.UseKeyExpiration = true; SendDlgItemMessage(IDC_DTPEXPIRATION, DTM_GETSYSTEMTIME, GDT_VALID, (LPARAM)&lpDate); kp.ExpirationYear = lpDate.wYear; kp.ExpirationMonth = lpDate.wMonth; kp.ExpirationDay = lpDate.wDay; } // Register After if (IsDlgButtonChecked(IDC_CHECKREGAFTER) != 0) { kp.UseRegisterAfter = true; SendDlgItemMessage(IDC_DTPREGAFTER, DTM_GETSYSTEMTIME, GDT_VALID, (LPARAM)&lpDate); kp.RegisterAfterYear = lpDate.wYear; kp.RegisterAfterMonth = lpDate.wMonth; kp.RegisterAfterDay = lpDate.wDay; } // Register Before if (IsDlgButtonChecked(IDC_CHECKREGBEFORE) != 0) { kp.UseRegisterBefore = true; SendDlgItemMessage(IDC_DTPREGBEFORE, DTM_GETSYSTEMTIME, GDT_VALID, (LPARAM)&lpDate); kp.RegisterBeforeYear = lpDate.wYear; kp.RegisterBeforeMonth = lpDate.wMonth; kp.RegisterBeforeDay = lpDate.wDay; } // Executions if (IsDlgButtonChecked(IDC_CHECKEXECS) != 0) { kp.UseExecutionsLimit = true; memset(&tmp, 0, sizeof(tmp)); GetDlgItemText(IDC_EDITEXECS, (char*)&tmp, sizeof(tmp)); kp.ExecutionsCount = atoi((char*)&tmp); } // Days if (IsDlgButtonChecked(IDC_CHECKDAYS) != 0) { kp.UseDaysLimit = true; memset(&tmp, 0, sizeof(tmp)); GetDlgItemText(IDC_EDITDAYS, (char*)&tmp, sizeof(tmp)); kp.DaysCount = atoi((char*)&tmp); } // Run-time if (IsDlgButtonChecked(IDC_CHECKRTIME) != 0) { kp.UseRunTimeLimit = true; memset(&tmp, 0, sizeof(tmp)); GetDlgItemText(IDC_EDITRTIME, (char*)&tmp, sizeof(tmp)); kp.RunTimeMinutes = atoi((char*)&tmp); } // Global time if (IsDlgButtonChecked(IDC_CHECKGTIME) != 0) { kp.UseGlobalTimeLimit = true; memset(&tmp, 0, sizeof(tmp)); GetDlgItemText(IDC_EDITGTIME, (char*)&tmp, sizeof(tmp)); kp.GlobalTimeMinutes = atoi((char*)&tmp); } // Country Lock if (IsDlgButtonChecked(IDC_CHECKCOUNTRY) != 0) { kp.UseCountyLimit = true; kp.CountryCode = KEY_COUNTRIES[com_counties.GetCurSel()].Code; } // Hardware ID if (IsDlgButtonChecked(IDC_CHECKHD) != 0) { kp.UseHardwareLocking = true; memset(&hardwareid, 0, sizeof(hardwareid)); GetDlgItemText(IDC_EDITHD, (char*)&hardwareid, sizeof(hardwareid)); kp.HardwareID = (char*)&hardwareid; } // Crypt Sections if (IsDlgButtonChecked(IDC_CHECKS1) != 0) { kp.EncryptedSections[0] = true; } if (IsDlgButtonChecked(IDC_CHECKS2) != 0) { kp.EncryptedSections[1] = true; } if (IsDlgButtonChecked(IDC_CHECKS3) != 0) { kp.EncryptedSections[2] = true; } if (IsDlgButtonChecked(IDC_CHECKS4) != 0) { kp.EncryptedSections[3] = true; } if (IsDlgButtonChecked(IDC_CHECKS5) != 0) { kp.EncryptedSections[4] = true; } if (IsDlgButtonChecked(IDC_CHECKS6) != 0) { kp.EncryptedSections[5] = true; } if (IsDlgButtonChecked(IDC_CHECKS7) != 0) { kp.EncryptedSections[6] = true; } if (IsDlgButtonChecked(IDC_CHECKS8) != 0) { kp.EncryptedSections[7] = true; } if (IsDlgButtonChecked(IDC_CHECKS9) != 0) { kp.EncryptedSections[8] = true; } if (IsDlgButtonChecked(IDC_CHECKS10) != 0) { kp.EncryptedSections[9] = true; } if (IsDlgButtonChecked(IDC_CHECKS11) != 0) { kp.EncryptedSections[10] = true; } if (IsDlgButtonChecked(IDC_CHECKS12) != 0) { kp.EncryptedSections[11] = true; } if (IsDlgButtonChecked(IDC_CHECKS13) != 0) { kp.EncryptedSections[12] = true; } if (IsDlgButtonChecked(IDC_CHECKS14) != 0) { kp.EncryptedSections[13] = true; } if (IsDlgButtonChecked(IDC_CHECKS15) != 0) { kp.EncryptedSections[14] = true; } if (IsDlgButtonChecked(IDC_CHECKS16) != 0) { kp.EncryptedSections[15] = true; } kp.KeyWithHyphens = IsDlgButtonChecked(IDC_CHECKHYPHENS) != 0; // Generate reg. key dwResult = KG_GenerateRegistrationKeyFromProject("default.enigma", &kp); if (dwResult == EP_NO_ERROR) { SetDlgItemText(IDC_EDITKEY, kp.Key); } else { char* sError; switch (dwResult) { case EP_ERROR_UNKNOWN: sError = "EP_ERROR_UNKNOWN"; break; case EP_ERROR_KEYBUFFEREMPTY: sError = "EP_ERROR_KEYBUFFEREMPTY"; break; case EP_ERROR_KEYBUFFERISLESS: sError = "EP_ERROR_KEYBUFFERISLESS"; break; case EP_ERROR_REGINFOEMPTY: sError = "EP_ERROR_REGINFOEMPTY"; break; case EP_ERROR_REGINFOTOOLARGE: sError = "EP_ERROR_REGINFOTOOLARGE"; break; case EP_ERROR_PRIVATEKEYISNOTSET: sError = "EP_ERROR_PRIVATEKEYISNOTSET"; break; case EP_ERROR_PUBLICKEYISNOTSET: sError = "EP_ERROR_PUBLICKEYISNOTSET"; break; case EP_ERROR_PRIVATEKEYISINVALID: sError = "EP_ERROR_PRIVATEKEYISINVALID"; break; case EP_ERROR_PUBLICKEYISINVALID: sError = "EP_ERROR_PUBLICKEYISINVALID"; break; case EP_ERROR_KEYMODEISINVALID: sError = "EP_ERROR_KEYMODEISINVALID"; break; case EP_ERROR_KEYBASEISINVALID: sError = "EP_ERROR_KEYBASEISINVALID"; break; case EP_ERROR_CURRENTDATEISINVALID: sError = "EP_ERROR_CURRENTDATEISINVALID"; break; case EP_ERROR_EXPIRATIONDATEISINVALID: sError = "EP_ERROR_EXPIRATIONDATEISINVALID"; break; case EP_ERROR_KEYISINVALID: sError = "EP_ERROR_KEYISINVALID"; break; case EP_ERROR_HARDWAREID: sError = "EP_ERROR_HARDWAREID"; break; case EP_ERROR_HARDWAREBUFFEREMPTY: sError = "EP_ERROR_HARDWAREBUFFEREMPTY"; break; case EP_ERROR_HARDWAREIDINVALIDFORKEY: sError = "EP_ERROR_HARDWAREIDINVALIDFORKEY"; break; case EP_ERROR_PROJECTFILENOTFOUND: sError = "EP_ERROR_PROJECTFILENOTFOUND"; break; case EP_ERROR_INVALIDPROJECTFILE: sError = "EP_ERROR_INVALIDPROJECTFILE"; break; case EP_ERROR_EXECUTIONSNUMBERINVALID: sError = "EP_ERROR_EXECUTIONSNUMBERINVALID"; break; case EP_ERROR_DAYSNUMBERINVALID: sError = "EP_ERROR_DAYSNUMBERINVALID"; break; case EP_ERROR_COUNTRYCODEINVALID: sError = "EP_ERROR_COUNTRYCODEINVALID"; break; case EP_ERROR_RUNTIMEINVALID: sError = "EP_ERROR_RUNTIMEINVALID"; break; case EP_ERROR_GLOBALTIMEINVALID: sError = "EP_ERROR_GLOBALTIMEINVALID"; break; case EP_ERROR_INSTALLBEFOREINVALID: sError = "EP_ERROR_INSTALLBEFOREINVALID"; break; case EP_ERROR_INSTALLAFTERINVALID: sError = "EP_ERROR_INSTALLAFTERINVALID"; break; default: sError = "Unknown error"; break; } SetDlgItemText(IDC_EDITKEY, sError); } }
private void btnGenerateFP_Click(object sender, EventArgs e) { tbKey.Clear(); if (tbUserInfo.Text == string.Empty) { MessageBox.Show("User info field is empty!"); return; } Enigma_KeyGen_IDE.TKeyGenParams kg = new Enigma_KeyGen_IDE.TKeyGenParams(); kg.KeyWithHyphens = cbHyphens.Checked; char[] keybuffer = new char[2048]; keybuffer.Initialize(); kg.Key = keybuffer.ToString(); kg.KeyLen = keybuffer.Length; kg.RegInfo = tbUserInfo.Text; kg.RegInfoLen = kg.RegInfo.Length; kg.UseKeyExpiration = cbExpiration.Checked; if (kg.UseKeyExpiration) { kg.ExpirationYear = dtpExpiration.Value.Year; kg.ExpirationMonth = dtpExpiration.Value.Month; kg.ExpirationDay = dtpExpiration.Value.Day; } // Hardware ID kg.UseHardwareLocking = cbHardware.Checked; if (kg.UseHardwareLocking) { kg.HardwareID = tbHardware.Text; } // Register After kg.UseRegisterAfter = cbRegisterAfter.Checked; if (kg.UseRegisterAfter) { kg.RegisterAfterYear = dtpRegisterAfter.Value.Year; kg.RegisterAfterMonth = dtpRegisterAfter.Value.Month; kg.RegisterAfterDay = dtpRegisterAfter.Value.Day; } // Register Before kg.UseRegisterBefore = cbRegisterBefore.Checked; if (kg.UseRegisterBefore) { kg.RegisterBeforeYear = dtpRegisterBefore.Value.Year; kg.RegisterBeforeMonth = dtpRegisterBefore.Value.Month; kg.RegisterBeforeDay = dtpRegisterBefore.Value.Day; } // Executions kg.UseExecutionsLimit = cbExecutions.Checked; if (kg.UseExecutionsLimit) { kg.ExecutionsCount = (int)udExecutions.Value; } // Days kg.UseDaysLimit = cbDays.Checked; if (kg.UseDaysLimit) { kg.DaysCount = (int)udDays.Value; } // Runtime kg.UseRunTimeLimit = cbRuntime.Checked; if (kg.UseRunTimeLimit) { kg.RunTimeMinutes = (int)udRuntime.Value; } // Global Time kg.UseGlobalTimeLimit = cbGlobalTime.Checked; if (kg.UseGlobalTimeLimit) { kg.GlobalTimeMinutes = (int)udGlobalTime.Value; } // Country kg.UseCountyLimit = cbCountry.Checked; if (kg.UseCountyLimit) { Enigma_KeyGen_IDE ide = new Enigma_KeyGen_IDE(); kg.CountryCode = ide.KEY_COUNTRIES[comCountries.SelectedIndex].Code; } kg.EncryptedSections = new byte[Enigma_KeyGen_IDE.NUMBER_OF_CRYPTED_SECTIONS]; kg.EncryptedSections[0] = Convert.ToByte(cbSection1.Checked); kg.EncryptedSections[1] = Convert.ToByte(cbSection2.Checked); kg.EncryptedSections[2] = Convert.ToByte(cbSection3.Checked); kg.EncryptedSections[3] = Convert.ToByte(cbSection4.Checked); kg.EncryptedSections[4] = Convert.ToByte(cbSection5.Checked); kg.EncryptedSections[5] = Convert.ToByte(cbSection6.Checked); kg.EncryptedSections[6] = Convert.ToByte(cbSection7.Checked); kg.EncryptedSections[7] = Convert.ToByte(cbSection8.Checked); kg.EncryptedSections[8] = Convert.ToByte(cbSection9.Checked); kg.EncryptedSections[9] = Convert.ToByte(cbSection10.Checked); kg.EncryptedSections[10] = Convert.ToByte(cbSection11.Checked); kg.EncryptedSections[11] = Convert.ToByte(cbSection12.Checked); kg.EncryptedSections[12] = Convert.ToByte(cbSection13.Checked); kg.EncryptedSections[13] = Convert.ToByte(cbSection14.Checked); kg.EncryptedSections[14] = Convert.ToByte(cbSection15.Checked); kg.EncryptedSections[15] = Convert.ToByte(cbSection16.Checked); // Generate reg. key uint dwResult = Enigma_KeyGen_IDE.KG_GenerateRegistrationKeyFromProject("default.enigma", ref kg); if (dwResult == Enigma_KeyGen_IDE.EP_NO_ERROR) { tbKey.Text = kg.Key; } else { switch (dwResult) { case Enigma_KeyGen_IDE.EP_ERROR_UNKNOWN: tbKey.Text = "EP_ERROR_UNKNOWN"; break; case Enigma_KeyGen_IDE.EP_ERROR_KEYBUFFEREMPTY: tbKey.Text = "EP_ERROR_KEYBUFFEREMPTY"; break; case Enigma_KeyGen_IDE.EP_ERROR_KEYBUFFERISLESS: tbKey.Text = "EP_ERROR_KEYBUFFERISLESS"; break; case Enigma_KeyGen_IDE.EP_ERROR_REGINFOEMPTY: tbKey.Text = "EP_ERROR_REGINFOEMPTY"; break; case Enigma_KeyGen_IDE.EP_ERROR_REGINFOTOOLARGE: tbKey.Text = "EP_ERROR_REGINFOTOOLARGE"; break; case Enigma_KeyGen_IDE.EP_ERROR_PRIVATEKEYISNOTSET: tbKey.Text = "EP_ERROR_PRIVATEKEYISNOTSET"; break; case Enigma_KeyGen_IDE.EP_ERROR_PUBLICKEYISNOTSET: tbKey.Text = "EP_ERROR_PUBLICKEYISNOTSET"; break; case Enigma_KeyGen_IDE.EP_ERROR_PRIVATEKEYISINVALID: tbKey.Text = "EP_ERROR_PRIVATEKEYISINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_PUBLICKEYISINVALID: tbKey.Text = "EP_ERROR_PUBLICKEYISINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_KEYMODEISINVALID: tbKey.Text = "EP_ERROR_KEYMODEISINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_KEYBASEISINVALID: tbKey.Text = "EP_ERROR_KEYBASEISINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_CURRENTDATEISINVALID: tbKey.Text = "EP_ERROR_CURRENTDATEISINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_EXPIRATIONDATEISINVALID: tbKey.Text = "EP_ERROR_EXPIRATIONDATEISINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_KEYISINVALID: tbKey.Text = "EP_ERROR_KEYISINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_HARDWAREID: tbKey.Text = "EP_ERROR_HARDWAREID"; break; case Enigma_KeyGen_IDE.EP_ERROR_HARDWAREBUFFEREMPTY: tbKey.Text = "EP_ERROR_HARDWAREBUFFEREMPTY"; break; case Enigma_KeyGen_IDE.EP_ERROR_HARDWAREIDINVALIDFORKEY: tbKey.Text = "EP_ERROR_HARDWAREIDINVALIDFORKEY"; break; case Enigma_KeyGen_IDE.EP_ERROR_PROJECTFILENOTFOUND: tbKey.Text = "EP_ERROR_PROJECTFILENOTFOUND"; break; case Enigma_KeyGen_IDE.EP_ERROR_INVALIDPROJECTFILE: tbKey.Text = "EP_ERROR_INVALIDPROJECTFILE"; break; case Enigma_KeyGen_IDE.EP_ERROR_EXECUTIONSNUMBERINVALID: tbKey.Text = "EP_ERROR_EXECUTIONSNUMBERINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_DAYSNUMBERINVALID: tbKey.Text = "EP_ERROR_DAYSNUMBERINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_COUNTRYCODEINVALID: tbKey.Text = "EP_ERROR_COUNTRYCODEINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_RUNTIMEINVALID: tbKey.Text = "EP_ERROR_RUNTIMEINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_GLOBALTIMEINVALID: tbKey.Text = "EP_ERROR_GLOBALTIMEINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_INSTALLBEFOREINVALID: tbKey.Text = "EP_ERROR_INSTALLBEFOREINVALID"; break; case Enigma_KeyGen_IDE.EP_ERROR_INSTALLAFTERINVALID: tbKey.Text = "EP_ERROR_INSTALLAFTERINVALID"; break; default: tbKey.Text = "Unknown error"; break; } } }
Private Sub bGenFP_Click() Dim kg As TKeyGenParams Dim I As Integer Dim dwResult As Long tKey.Text = vbNullString If tbUserInfo.Text = vbNullString Then MsgBox "User info field is empty!" Exit Sub End If ' Hyphens kg.KeyWithHyphens = cbHyphens.Value ' Fill key buffer kg.Key = String$(2048, 0) kg.KeyLen = 2048 ' Fill User Info buffer kg.RegInfo = tbUserInfo.Text kg.RegInfoLen = Len(tbUserInfo.Text) ' Key expiration info kg.UseKeyExpiration = cbExpiration.Value If kg.UseKeyExpiration Then kg.ExpirationDay = dtpExpiration.Day kg.ExpirationMonth = dtpExpiration.Month kg.ExpirationYear = dtpExpiration.Year End If ' Register After kg.UseRegisterAfter = cbRegisterAfter.Value If kg.UseRegisterAfter Then kg.RegisterAfterDay = dtpRegisterAfter.Day kg.RegisterAfterMonth = dtpRegisterAfter.Month kg.RegisterAfterYear = dtpRegisterAfter.Year End If ' Register Before kg.UseRegisterBefore = cbRegisterBefore.Value If kg.UseRegisterBefore Then kg.RegisterBeforeDay = dtpRegisterBefore.Day kg.RegisterBeforeMonth = dtpRegisterBefore.Month kg.RegisterBeforeYear = dtpRegisterBefore.Year End If ' Executions kg.UseExecutionsLimit = cbExecutions.Value If kg.UseExecutionsLimit Then kg.ExecutionsCount = tExecutions.Text End If ' Days kg.UseDaysLimit = cbDays.Value If kg.UseDaysLimit Then kg.DaysCount = tDays.Text End If ' Runtime kg.UseRunTimeLimit = cbRuntime.Value If kg.UseRunTimeLimit Then kg.RunTimeMinutes = tRuntime.Text End If ' Global Time kg.UseGlobalTimeLimit = cbGlobalTime.Value If kg.UseGlobalTimeLimit Then kg.GlobalTimeMinutes = tGlobalTime.Text End If ' Country kg.UseCountyLimit = cbCountry.Value If kg.UseCountyLimit Then kg.CountryCode = comCountries.ItemData(comCountries.ListIndex) End If ' Hardware ID kg.UseHardwareLocking = cbHardware.Value If kg.UseHardwareLocking Then kg.HardwareID = tHardware.Text End If ' Crypt Sections For I = 1 To NUMBER_OF_CRYPTED_SECTIONS kg.EncryptedSections(I - 1) = cbSection(I - 1).Value Next I ' Generate reg. key dwResult = KG_GenerateRegistrationKeyFromProject("default.enigma", kg) If dwResult = ERROR_OK Then tKey.Text = kg.Key Else Select Case dwResult Case EP_ERROR_UNKNOWN tKey.Text = "EP_ERROR_UNKNOWN" Case EP_ERROR_KEYBUFFEREMPTY tKey.Text = "EP_ERROR_KEYBUFFEREMPTY" Case EP_ERROR_KEYBUFFERISLESS tKey.Text = "EP_ERROR_KEYBUFFERISLESS" Case EP_ERROR_REGINFOEMPTY tKey.Text = "EP_ERROR_REGINFOEMPTY" Case EP_ERROR_REGINFOTOOLARGE tKey.Text = "EP_ERROR_REGINFOTOOLARGE" Case EP_ERROR_PRIVATEKEYISNOTSET tKey.Text = "EP_ERROR_PRIVATEKEYISNOTSET" Case EP_ERROR_PUBLICKEYISNOTSET tKey.Text = "EP_ERROR_PUBLICKEYISNOTSET" Case EP_ERROR_PRIVATEKEYISINVALID tKey.Text = "EP_ERROR_PRIVATEKEYISINVALID" Case EP_ERROR_PUBLICKEYISINVALID tKey.Text = "EP_ERROR_PUBLICKEYISINVALID" Case EP_ERROR_KEYMODEISINVALID tKey.Text = "EP_ERROR_KEYMODEISINVALID" Case EP_ERROR_KEYBASEISINVALID tKey.Text = "EP_ERROR_KEYBASEISINVALID" Case EP_ERROR_CURRENTDATEISINVALID tKey.Text = "EP_ERROR_CURRENTDATEISINVALID" Case EP_ERROR_EXPIRATIONDATEISINVALID tKey.Text = "EP_ERROR_EXPIRATIONDATEISINVALID" Case EP_ERROR_KEYISINVALID tKey.Text = "EP_ERROR_KEYISINVALID" Case EP_ERROR_HARDWAREID tKey.Text = "EP_ERROR_HARDWAREID" Case EP_ERROR_HARDWAREBUFFEREMPTY tKey.Text = "EP_ERROR_HARDWAREBUFFEREMPTY" Case EP_ERROR_HARDWAREIDINVALIDFORKEY tKey.Text = "EP_ERROR_HARDWAREIDINVALIDFORKEY" Case EP_ERROR_PROJECTFILENOTFOUND tKey.Text = "EP_ERROR_PROJECTFILENOTFOUND" Case EP_ERROR_INVALIDPROJECTFILE tKey.Text = "EP_ERROR_INVALIDPROJECTFILE" Case EP_ERROR_EXECUTIONSNUMBERINVALID tKey.Text = "EP_ERROR_EXECUTIONSNUMBERINVALID" Case EP_ERROR_DAYSNUMBERINVALID tKey.Text = "EP_ERROR_DAYSNUMBERINVALID" Case EP_ERROR_COUNTRYCODEINVALID tKey.Text = "EP_ERROR_COUNTRYCODEINVALID" Case EP_ERROR_RUNTIMEINVALID tKey.Text = "EP_ERROR_RUNTIMEINVALID" Case EP_ERROR_GLOBALTIMEINVALID tKey.Text = "EP_ERROR_GLOBALTIMEINVALID" Case EP_ERROR_INSTALLBEFOREINVALID tKey.Text = "EP_ERROR_INSTALLBEFOREINVALID" Case EP_ERROR_INSTALLAFTERINVALID tKey.Text = "EP_ERROR_INSTALLAFTERINVALID" Case Else tKey.Text = "Unknown error" End Select End If End Sub 在程序安装目录可查看函数更多实例,如 Examples\Keygen 子文件夹。 |
The Enigma Protector in - China http://enigmaprotector.cn - India https://enigmaprotector.in
Copyright © 2004-2023, The Enigma Protector Developers Team. All rights reserved.