private int GetKey() { int key = 0; status = hasp.Login(VendorCode.Code_AZIOK); if (status == HaspStatus.StatusOk || status == HaspStatus.NoTime) { key = 1; } if (key == 0) { status = hasp.Login(VendorCode.Code_YWYZX); if (status == HaspStatus.StatusOk || status == HaspStatus.NoTime) { key = 2; } } if (key == 0) { status = hasp.Login(VendorCode.Code_QTZED); if (status == HaspStatus.StatusOk || status == HaspStatus.NoTime) { key = 3; } } return(key); }
public void FirstTest(double[] Param1) { try { if (m_objHasp != null && m_objHasp1 != null) { HaspStatus objStatus = m_objHasp.Login(decrypt(SCONSTTEST)); HaspStatus objStatus1 = m_objHasp1.Login(decrypt(SCONSTTEST)); if (HaspStatus.AlreadyLoggedIn == objStatus) { m_objHasp.Logout(); } if (HaspStatus.StatusOk != objStatus && HaspStatus.AlreadyLoggedIn == objStatus) { m_objHasp.Login(decrypt(SCONSTTEST)); } if (HaspStatus.AlreadyLoggedIn == objStatus1) { m_objHasp1.Logout(); } if (HaspStatus.StatusOk != objStatus && HaspStatus.AlreadyLoggedIn == objStatus1) { m_objHasp1.Login(decrypt(SCONSTTEST)); } m_objHasp.Encrypt(Param1); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message, ex.StackTrace); } }
public string ExtractInstrumentName() { string currentName = null; try { PublicClass.InstrumentSerial = ""; vendorCode = m_sTest; hasp = new Hasp(new HaspFeature(10)); status = hasp.Login(vendorCode); featureStatus = status.ToString(); Int32 offset = 0; Int32 size = 48; byte[] data = new byte[size]; HaspFile file = hasp.GetFile(HaspFileId.ReadWrite); file.FilePos = offset; status = file.Read(data, 0, data.Length); currentName = Encoding.ASCII.GetString(data).TrimEnd(new char[] { '\0' }); string[] insName = currentName.Split(new string[] { "|" }, StringSplitOptions.None); currentName = insName[0]; PublicClass.InstrumentSerial = insName[1]; } catch (Exception ex) { } return(currentName); }
private void ToolStripMenuItemSaveAs_Click(object sender, EventArgs e) { HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(_vendorCode); var haspStatus = getHaspStatusMessage(status); if (haspStatus != "OK") { var res = MessageBox.Show( "HASP HL key has been removed. If you need to save the file, click Cancel and save it", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error ); if (res == DialogResult.OK) { Close(); } } SaveFile(); }
public string loginstate(string slCode) { HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(safeNetEntity.vendorCode, safeNetEntity.loginScope.Replace("{slcode}", slCode)); return(status.ToString()); }
/// <summary> /// 返回ID /// </summary> /// <param name="tz">厂商</param> /// <param name="id">ID</param> /// <param name="er">错误代码</param> /// <returns></returns> public HaspStatus time(int tz, out string id, out string er) { id = string.Empty; er = string.Empty; try { string DateTime = string.Empty; scope = defaultScope; HaspFeature feature = HaspFeature.FromFeature(tz); hasp = new Hasp(feature); HaspStatus status = hasp.Login(strVendorCode, scope); if (status != HaspStatus.StatusOk) { er = status.ToString(); return(status); } er = Convert.ToString(status); string xlmFile = "<haspformat root=" + "\"" + "hasp_info" + "\"" + ">" + "<hasp>" + "<attribute name=" + "\"" + "id" + "\"" + "/>" + "<feature>" + "<element name=" + "\"" + "license" + "\"" + "/>" + "</feature>" + "</hasp>" + "</haspformat>"; string info = string.Empty; string Time2 = hasp.GetSessionInfo(xlmFile, ref info).ToString(); string[] sArray = info.Split(new char[2] { '"', '"' }); if (sArray.Length > 6) { id = sArray[5]; } //释放内存 status = hasp.Logout(); return(status); } catch (Exception ex) { er = ex.ToString(); return(HaspStatus.SystemError); } }
/// <summary> /// Uses pre-defined vendor code for validating whether the HASP software license installed on the server is valid or not /// Returns the detailed hasp pass/fail message only /// </summary> /// <remarks> /// The HASP dlls (hasp_net_windows.dll, hasp_windows_x64_102489.dll, haspvlib_102489.dll, and hasp_windows_102489.dll) /// must be placed in the windows system directory in order for IIS to access those external dlls /// </remarks> public static string validateLicenseDetails() { // Sentinel LDK API HaspFeature feature = HaspFeature.FromFeature(1001); // Using feature 1 defined in EMS-Server; Actual product should be using 1001 Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(getVendorCode()); return(status.ToString()); }
internal void Open() { Hasp = new Hasp(HaspFeature.Default); // Используется feature по умолчанию (ID=0), которая всегда есть на ключе. HaspStatus status = Hasp.Login(VendorCode); if (HaspStatus.StatusOk != status) { throw new HaspException(status, "Log in failed."); } }
public bool CheckLicense() { var hasp = new Hasp(_feature); var status = hasp.Login(_vendorCode); if (status == HaspStatus.StatusOk) { status = hasp.Logout(); return true; } return false; }
public bool login(string slCode) { bool rtn = false; HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(safeNetEntity.vendorCode, safeNetEntity.loginScope.Replace("{slcode}", slCode)); if (HaspStatus.StatusOk == status) { rtn = true; } return(rtn); }
/// <summary> /// Demonstrates how to perform a login using the default /// feature and how to perform an automatic logout /// using the Hasp's Dispose method. /// </summary> public void LoginDisposeDemo() { Verbose("Login/Dispose Demo with Default Feature (HaspFeature.Default)"); HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(VendorCode.Code, scope); ReportStatus(status); Verbose("Disposing object - will perform an automatic logout"); hasp.Dispose(); Verbose(""); }
/// <summary> /// Uses pre-defined vendor code for validating whether the HASP software license installed on the server is valid or not /// </summary> /// <remarks> /// The HASP dlls (hasp_net_windows.dll, hasp_windows_x64_102489.dll, haspvlib_102489.dll, and hasp_windows_102489.dll) /// must be placed in the windows system directory in order for IIS to access those external dlls /// </remarks> public static bool validateLicense() { // Sentinel LDK API HaspFeature feature = HaspFeature.FromFeature(1001); // Using feature 1 defined in EMS-Server; Actual product should be using 1001 Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(getVendorCode()); if (HaspStatus.StatusOk != status) { return(false); } else { return(true); } }
/// <summary> /// Demonstrates how to perform a login and an automatic /// logout using C#'s scope clause. /// </summary> public void LoginDefaultAutoDemo() { Verbose("Login Demo with Default Feature (HaspFeature.Default)"); HaspFeature feature = HaspFeature.Default; // this will perform a logout and object disposal // when the using scope is left. using (Hasp hasp = new Hasp(feature)) { HaspStatus status = hasp.Login(VendorCode.Code, scope); ReportStatus(status); Verbose("Object going out of scope - System will call Dispose"); } Verbose(""); }
/// <summary> /// Demonstrates how to login using a feature id. /// </summary> public Hasp LoginDemo(HaspFeature feature) { //Verbose("Login Demo with Feature: " + // feature.FeatureId.ToString() + // (feature.IsProgNum ? " (Program Number)" : "")); // create a key object using a feature // and perform a login using the vendor code. Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(VendorCode.Code, scope); ReportStatus(status); //Verbose(""); return(hasp.IsLoggedIn() ? hasp : null); }
private void FormMain_Load(object sender, EventArgs e) { HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(_vendorCode); var haspStatus = getHaspStatusMessage(status); if (Properties.Settings.Default.number_of_starts < 5 && haspStatus == "OK") { Properties.Settings.Default.hasp_plugged_in = true; } if (haspStatus != "OK" && Properties.Settings.Default.hasp_plugged_in) { var res = MessageBox.Show( "The key was plugged in once. Plug it in again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); if (res == DialogResult.OK) { Close(); } } if (Properties.Settings.Default.number_of_starts >= 5 && haspStatus != "OK") { var res = MessageBox.Show( haspStatus, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); if (res == DialogResult.OK) { Close(); } } }
public HaspStatus loginInHasp() { //HaspFeature feature = HaspFeature.FromFeature(10); HaspFeature feature = HaspFeature.FromFeature(50); string scope = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<haspscope>" + " <hasp type=\"HASP-HL\" />" + "</haspscope>"; hasp = new Hasp(feature); //HaspStatus status = hasp.Login(VendorCode.Code); HaspStatus status = hasp.Login(VendorCode.Code, scope); // mensagem = exibeMensagem(status, "Login no HASP efetuado com sucesso!"); logger.logInfo("#loginInHasp - " + MapaDeStatus.getStatus((int) status)); return status; }
/// <summary> /// Demonstrates how to login into a key using the /// default feature. The default feature is ALWAYS /// available in every key. /// </summary> public Hasp LoginDefaultDemo() { Verbose("Login Demo with Default Feature (HaspFeature.Default)"); HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(VendorCode.Code, scope); ReportStatus(status); Verbose(""); // Please note that there is no need to call // a logout function explicitly - although it is // recommended. The garbage collector will perform // the logout when disposing the object. // If you need more control over the logout procedure // perform one of the more advanced tasks. return(hasp.IsLoggedIn() ? hasp : null); }
private void ToolStripMenuItemOpen_Click(object sender, EventArgs e) { HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(_vendorCode); var haspStatus = getHaspStatusMessage(status); if (haspStatus != "OK") { var res = MessageBox.Show( "HASP HL key has been removed. If you need to save the file, click Cancel and save it", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error ); if (res == DialogResult.OK) { Close(); } } OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { _openedFile = openFileDialog.FileName; try { richTextBoxMain.Text = File.ReadAllText(_openedFile); } catch (Exception err) { throw err; } } }
/// <summary> /// Demonstrates how to perform a login and a logout /// using the default feature. /// </summary> public void LoginLogoutDefaultDemo() { HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(VendorCode.Code, scope); ReportStatus(status); if (HaspStatus.StatusOk == status) { status = hasp.Logout(); ReportStatus(status); } // recommended, but not mandatory // this call ensures that all resources to the key // are freed immediately. hasp.Dispose(); }
/// <summary> /// 打开加密狗 /// </summary> /// <param name="tz">厂商</param> /// <param name="pwr">天数</param> /// <param name="er">错误代码</param> /// <returns></returns> public HaspStatus ClassCS(int tz, out int leftDays, out int er) { leftDays = -1; er = -1; try { string pwr = string.Empty; scope = defaultScope; HaspFeature feature = HaspFeature.FromFeature(tz); hasp = new Hasp(feature); HaspStatus status = hasp.Login(strVendorCode, scope); if (status != HaspStatus.StatusOk) { pwr = "0"; er = (int)status; return(status); } DateTime time3 = new DateTime(); hasp.GetRtc(ref time3); int len = 10; byte[] bytes = new byte[len]; HaspFile file = hasp.GetFile(HaspFileId.ReadWrite); status = file.Read(bytes, 0, bytes.Length); pwr = System.Text.Encoding.UTF8.GetString(bytes); pwr = pwr.Replace("\0", ""); DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(pwr); TimeSpan toNow = new TimeSpan(lTime); DateTime dtResult = dtStart.Add(toNow); int dayTime = (int)(Convert.ToInt32(pwr) / 3600 / 24); DateTime time4 = dtResult.AddDays(dayTime); TimeSpan sp = time4.Subtract(time3); leftDays = sp.Days; er = (int)status; return(status); } catch (Exception) { return(HaspStatus.SystemError); } }
/// <summary> /// 返回天数 /// </summary> /// <param name="tz">厂商</param> /// <param name="pwr">激活码</param> /// <param name="day">天数</param> /// <returns></returns> public HaspStatus ActivationTime(int tz, string pwr, out int day) { scope = defaultScope; HaspFeature feature = HaspFeature.FromFeature(tz); hasp = new Hasp(feature); HaspStatus status = hasp.Login(strVendorCode, scope); if (pwr.Length != 16) { status = HaspStatus.TimeError; day = 0; return(status); } if (status != HaspStatus.StatusOk) { day = 0; return(status); } DateTime time = new DateTime(); hasp.GetRtc(ref time); HaspFile file = hasp.GetFile(HaspFileId.ReadWrite); byte[] _bytes = new byte[16]; DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); if (pwr.Contains("6216")) { String[] arr = new String[5]; byte[] bytes = new byte[80]; file.FilePos = 16; status = file.Read(bytes, 0, bytes.Length); string _pwr = System.Text.Encoding.UTF8.GetString(bytes); for (int i = 0; i < arr.Length; i++) { arr[i] = _pwr.Substring(i * 16, 16); if (pwr.Equals(arr[i])) { file.FilePos = (16 * i) + 16; Thread.Sleep(10); status = file.Write(_bytes, 0, _bytes.Length); DateTime time3 = time.AddDays(30); long time2 = (long)(time3 - dtStart).TotalSeconds; string _time = time2.ToString(); byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time); file.FilePos = 0; status = file.Write(decoded, 0, decoded.Length); day = 30; return(status); } } } else if (pwr.Contains("6217")) { byte[] bytes = new byte[80]; file.FilePos = 96; status = file.Read(bytes, 0, bytes.Length); string _pwr = System.Text.Encoding.UTF8.GetString(bytes); String[] arr = new String[5]; for (int i = 0; i < arr.Length; i++) { arr[i] = _pwr.Substring(i * 16, 16); if (pwr.Equals(arr[i])) { file.FilePos = (16 * i) + 96; Thread.Sleep(10); status = file.Write(_bytes, 0, _bytes.Length); DateTime time3 = time.AddDays(60); long time2 = (long)(time3 - dtStart).TotalSeconds; string _time = time2.ToString(); byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time); file.FilePos = 0; status = file.Write(decoded, 0, decoded.Length); day = 60; return(status); } } } else if (pwr.Contains("6218")) { byte[] bytes = new byte[80]; file.FilePos = 176; status = file.Read(bytes, 0, bytes.Length); string _pwr = System.Text.Encoding.UTF8.GetString(bytes); String[] arr = new String[8]; for (int i = 0; i < arr.Length; i++) { arr[i] = _pwr.Substring(i * 16, 16); if (pwr.Equals(arr[i])) { file.FilePos = (16 * i) + 176; Thread.Sleep(10); status = file.Write(_bytes, 0, _bytes.Length); DateTime time3 = time.AddDays(90); long time2 = (long)(time3 - dtStart).TotalSeconds; string _time = time2.ToString(); byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time); file.FilePos = 0; status = file.Write(decoded, 0, decoded.Length); day = 90; return(status); } } } else if (pwr.Contains("6219")) { byte[] bytes = new byte[16]; file.FilePos = 256; status = file.Read(bytes, 0, bytes.Length); string _pwr = System.Text.Encoding.UTF8.GetString(bytes); String[] arr = new String[1]; for (int i = 0; i < arr.Length; i++) { arr[i] = _pwr.Substring(i * 16, 16); if (pwr.Equals(arr[i])) { DateTime time3 = time.AddDays(999); long time2 = (long)(time3 - dtStart).TotalSeconds; string _time = time2.ToString(); byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time); file.FilePos = 0; status = file.Write(decoded, 0, decoded.Length); day = 999; return(status); } } } else { status = HaspStatus.TimeError; day = 0; return(status); } status = HaspStatus.SystemError; day = 0; return(status); }