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 static string GetInfo(string scope, string format, bool checkBeforeLogin = false) { string info = null; HaspStatus getStatus = HaspStatus.AlreadyLoggedOut; if (Variables.myStatus == HaspStatus.StatusOk && !checkBeforeLogin) { getStatus = Hasp.GetInfo(scope, format, Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], ref info); if (getStatus == HaspStatus.StatusOk) { return(info); } else { return(getStatus.ToString()); } } else if (checkBeforeLogin) { getStatus = Hasp.GetInfo(scope, format, Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], ref info); if (getStatus == HaspStatus.StatusOk) { return(info); } else { return(getStatus.ToString()); } } return(getStatus.ToString()); }
internal string rehost(string slcode, string recipient) { string info = null; HaspStatus status = Hasp.Transfer(safeNetEntity.actionRehost.Replace("{slcode}", slcode), safeNetEntity.scopeRehost.Replace("{slcode}", slcode), safeNetEntity.vendorCode, recipient, ref info); return(status == HaspStatus.StatusOk ? info : ((int)status + status.ToString())); }
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 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); }
public bool SecondTest(byte[] Param2) { try { if (m_objHasp != null && m_objHasp1 != null) { m_objHasp.Logout(); m_objHasp1.Logout(); HaspStatus objStatus = m_objHasp.Login(decrypt(SCONSTTEST)); HaspStatus objStatus1 = m_objHasp1.Login(decrypt(SCONSTTEST)); if (HaspStatus.StatusOk == objStatus || HaspStatus.StatusOk == objStatus1 || HaspStatus.AlreadyLoggedIn == objStatus || HaspStatus.AlreadyLoggedIn == objStatus1) { return(true); } else { return(false); } } else { return(false); } } catch (Exception ex) { return(m_bAcknowledgement); System.Diagnostics.Debug.WriteLine(ex.Message, ex.StackTrace); } }
/// <summary> /// 获取C2V XML /// </summary> /// <returns></returns> internal string getC2VXML() { string info = null; HaspStatus status = Hasp.GetInfo(safeNetEntity.scope, safeNetEntity.formatC2V, safeNetEntity.vendorCode, ref info); return(info); }
public string readInHasp(ref HaspStatus status, ref string mensagem) { HaspFile file = hasp.GetFile(HaspFileId.ReadWrite); int size = SIZE_MEMORY; byte[] data = new byte[size]; status = file.Read(data, 0, data.Length); mensagem = showMessage(status, "Leitura efetuada com sucesso!"); status = hasp.Decrypt(data); System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); string dadosDecriptados = enc.GetString(data); dadosDecriptados = dadosDecriptados.Replace("\0", String.Empty); logger.logInfo("#readInHasp - Dados decriptados:[" + dadosDecriptados + "]"); //MessageBox.Show("Lido:[" + dadosDecriptados + "]", FORM_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); logger.logInfo("#readInHasp - " + mensagem); //stringToHarklock(dadosDecriptados.Trim()); return dadosDecriptados; }
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 WriteLicense(License inLicense, int inLicNr, bool replace) { MESSAGE_LOG_HEADER_STRUCT2 temp2; temp2.mClient = Convert.ToUInt16(inLicense.mClient); temp2.mCRC = inLicense.mCRC; temp2.mEnd = Convert.ToUInt16(inLicense.mEnd); temp2.mKey = Convert.ToByte(inLicense.mKey); temp2.mProduct = Convert.ToUInt16(inLicense.mProduct); temp2.mStart = Convert.ToUInt16(inLicense.mStart); byte[] all = null; byte[] licensesbytes = null; licensesbytes = new byte[2]; all = new byte[12]; all = RawSerialize(temp2); file.FilePos = 24 + (inLicNr * 12); // client id status = file.Write(all, 0, 12); // and put license count on 1 file.FilePos = 6; // and the number of licenses licensesbytes = BitConverter.GetBytes((uint)mLicenseCount + (replace?0:1)); status = file.Write(licensesbytes, 0, 2); }
/// <summary> /// 生成SAFENET证书 /// </summary> /// <param name="productKey"></param> /// <returns></returns> internal bool installSafeNet(string productKey, out string slId, out string msg) { msg = null; slId = null; try { string v2c = getV2C(productKey, out msg); string refXml = null; if (!string.IsNullOrEmpty(v2c)) { xmlBiz bll = new xmlBiz(); XmlDocument xml = bll.getXmlDocument(v2c.ToString()); XmlNode haspInfo = bll.getXmlSingleNode(xml, "hasp_info"); XmlNode haspscope = bll.getXmlSingleNode(haspInfo, "haspscope"); XmlNode vendor = bll.getXmlSingleNode(haspscope, "vendor"); XmlNode hasp = bll.getXmlSingleNode(vendor, "hasp"); slId = bll.getXmlAttribute(hasp, "id"); } HaspStatus status = Hasp.Update(v2c, ref refXml); return(status == HaspStatus.StatusOk); } catch (Exception ex) { msg += ex.Message + ex.StackTrace; return(false); } }
private static string getHaspStatusMessage(HaspStatus status) { string statusText; switch (status) { case HaspStatus.ContainerNotFound: statusText = "Evaluation is expired! Plug in your HASP HL key and restart the application."; break; case HaspStatus.DriverNotFound: statusText = "Please install HASP HL driver and try again"; break; case HaspStatus.StatusOk: statusText = "OK"; break; default: statusText = status.ToString(); break; } return(statusText); }
/// <summary> /// Demonstrates how to use to retrieve a XML containing all available features. /// </summary> public void GetInfoDemo() { string queryFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<haspformat root=\"hasp_info\">" + " <feature>" + " <attribute name=\"id\" />" + " <element name=\"license\" />" + " </feature>" + "</haspformat>"; Verbose("Get Information Demo"); Verbose("Retrieving Feature Information"); string info = null; HaspStatus status = Hasp.GetInfo(scope, queryFormat, VendorCode.Code, ref info); ReportStatus(status); if (HaspStatus.StatusOk == status) { Verbose("Fature Information:"); Verbose(info.Replace("\n", "\r\n ")); } else { Verbose(""); } }
/// <summary> /// Demonstrates how to retrieve information from a key. /// </summary> public void SessionInfoDemo(Hasp hasp) { // sanity check if ((null == hasp) || !hasp.IsLoggedIn()) { return; } Verbose("Get Session Information Demo"); Verbose("Retrieving Key Information"); // firstly we will retrieve the key info. string info = null; HaspStatus status = hasp.GetSessionInfo(Hasp.KeyInfo, ref info); ReportStatus(status); if (HaspStatus.StatusOk == status) { Verbose("Key Information:"); Verbose(info.Replace("\n", "\r\n ")); } else { Verbose(""); } Verbose("Retrieving Session Information"); // next the session info. status = hasp.GetSessionInfo(Hasp.SessionInfo, ref info); ReportStatus(status); if (HaspStatus.StatusOk == status) { Verbose("Session Information:"); Verbose(info.ToString()); } else { Verbose(""); } Verbose("Retrieving Update Information"); // last the update information. status = hasp.GetSessionInfo(Hasp.UpdateInfo, ref info); ReportStatus(status); if (HaspStatus.StatusOk == status) { Verbose("Update Information:"); Verbose(info.ToString()); } else { Verbose(""); } }
private void FormMain_FormClosing(object sender, FormClosingEventArgs e) { HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Logout(); getHaspStatusMessage(status); }
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()); }
public static string CancelDetachViaLicensingApi(string parentKeyId) { var myId = GetInfo(Variables.scopeForLocal, Variables.formatForGetId); string info = null; HaspStatus myCancelDetachStatus = Hasp.Transfer(Variables.actionForCancelDetach.Replace("{KEY_ID}", parentKeyId), Variables.scopeForSpecificKeyId.Replace("{KEY_ID}", parentKeyId), Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], myId, ref info); return(myCancelDetachStatus.ToString()); }
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> /// 获取C2V XML /// </summary> /// <returns></returns> internal string getImmigrationXML() { string info = null; HaspStatus status = Hasp.GetInfo(safeNetEntity.scope, safeNetEntity.formatImmigration, safeNetEntity.vendorCode, ref info); if (status == HaspStatus.StatusOk) { return(info); } else { return((int)status + status.ToString()); } }
public bool logout() { bool rtn = false; HaspFeature feature = HaspFeature.Default; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Logout(); if (HaspStatus.StatusOk == status) { rtn = true; } return(rtn); }
internal string TransferToolupdate(string v2c) { string refXml = null; HaspStatus status = Hasp.Update(v2c, ref refXml); if (status == HaspStatus.StatusOk) { refXml = "ok"; } else { refXml = ((int)status + status.ToString()); } return(refXml); }
/// <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> /// Dumps an operation status into the /// referenced TextBox. /// </summary> public void ReportStatus(HaspStatus status) { Debug.Log(string.Format(" Result: {0} (HaspStatus::{1})\r\n", stringCollection[(int)status], status.ToString())); //FormHaspDemo.WriteToTextbox(textHistory, // string.Format(" Result: {0} (HaspStatus::{1})\r\n", // stringCollection[(int)status], // status.ToString())); //if (textHistory != null) //{ // if (HaspStatus.StatusOk == status) // textHistory.Refresh(); // else // textHistory.Parent.Refresh(); //} }
/// <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> /// 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); }
public static void GetProgramLicenseDataFromMemoryField() { HaspFile file = HaspData.GetFile(HaspFileId.ReadWrite); byte[] data = new byte[ProgramLicense.MaxMemory]; HaspStatus status = file.Read(data, 0, data.Length); // Should redefine memory writting styles between 'ePM-Ex', 'Kohyoung', 'EAP' and 'MES' in 'NKHardLockInfo' class if (HaspStatus.StatusOk == status) { switch (ProgramLicense.MemoryType) { case NKLicenseList.MemoryType.ePM_Ex: // Check OptionCode int preYear = DateTime.Now.Year / 100 * 100; int year = ParseHexintToInt(data[10]); int month = ParseHexintToInt(data[11]); int day = DateTime.DaysInMonth(year, month); ProgramLicense.ServiceExpirationDate = new DateTime(preYear + year, month, day, 23, 59, 59); // Check LicenseCode year = ParseHexintToInt(data[24]); month = ParseHexintToInt(data[25]); day = ParseHexintToInt(data[26]); ProgramLicense.ManufacturedDate = new DateTime(preYear + year, month, day); break; case NKLicenseList.MemoryType.Kohyoung: break; case NKLicenseList.MemoryType.EAP: break; case NKLicenseList.MemoryType.MES: break; default: break; } } }
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(); } } }
/// <summary> /// Performs a logout operation on the key. /// </summary> public void LogoutDemo(ref Hasp hasp) { // sanity check if ((null == hasp) || !hasp.IsLoggedIn()) { return; } Verbose("Logout Demo"); HaspStatus status = hasp.Logout(); ReportStatus(status); // get rid of the key immediately. hasp.Dispose(); hasp = null; Verbose(""); }
private string exibeMensagem(HaspStatus status, string msgSucesso) { string alert = ""; if (HaspStatus.StatusOk != status) { alert = "ERRO: [" + HardLockHelper.MapaDeStatus.getStatus((int)status) + "]"; MessageBox.Show(alert, FORM_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); logger.logError("#exibeMensagem - " + alert); } else { alert = msgSucesso; MessageBox.Show(alert, FORM_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); logger.logInfo("#exibeMensagem - " + alert); } return alert; }
internal HaspException(HaspStatus haspStatus, string message) : this(message) { _haspStatus = Convert.ToInt32(haspStatus); }
private string showMessage(HaspStatus status, string msgSucesso) { MessageBoxIcon mbi = MessageBoxIcon.Information; string alert = ""; if (HaspStatus.StatusOk != status) { alert = "ERRO: [" + mpst.getStatus((int)status) + "]"; mbi = MessageBoxIcon.Error; logger.logError(alert); } else { alert = msgSucesso; logger.logInfo(alert); } MessageBox.Show(alert, FORM_CAPTION, MessageBoxButtons.OK, mbi); return alert; }