public bool SecondTest(double[] Param2) { try { if (m_objHasp != null) { HaspStatus objStatus = m_objHasp.Login(decrypt(SCONSTTEST)); HaspStatus objDecryption = m_objHasp.Decrypt(Param2); if (HaspStatus.StatusOk == objStatus && HaspStatus.StatusOk == objDecryption) { m_bAcknowledgement = true; } } return(m_bAcknowledgement); } catch (Exception ex) { return(m_bAcknowledgement); System.Diagnostics.Debug.WriteLine(ex.Message, ex.StackTrace); } }
/// <summary> /// Demonstrates the usage of the AES encryption and /// decryption methods. /// </summary> public void EncryptDecryptDemo(Hasp hasp) { // sanity check if ((null == hasp) || !hasp.IsLoggedIn()) { return; } Verbose("Encrypt/Decrypt Demo"); // the string to be encryted/decrypted. string text = "Sentinel LDK is great"; Verbose("Encrypting \"" + text + "\""); // convert the string into a byte array. byte[] data = UTF8Encoding.Default.GetBytes(text); // encrypt the data. HaspStatus status = hasp.Encrypt(data); ReportStatus(status); if (HaspStatus.StatusOk == status) { text = UTF8Encoding.Default.GetString(data); Verbose("Encrypted string: \"" + text + "\""); Verbose(""); Verbose("Decrypting \"" + text + "\""); // decrypt the data. // on success we convert the data back into a // human readable string. status = hasp.Decrypt(data); ReportStatus(status); if (HaspStatus.StatusOk == status) { text = UTF8Encoding.Default.GetString(data); Verbose("Decrypted string: \"" + text + "\""); } } Verbose(""); // Second choice - encrypting a string using the // native .net API text = "Encrypt/Decrypt String"; Verbose("Encrypting \"" + text + "\""); status = hasp.Encrypt(ref text); ReportStatus(status); if (HaspStatus.StatusOk == status) { Verbose("Encrypted string: \"" + text + "\""); Verbose(""); Verbose("Decrypting \"" + text + "\""); status = hasp.Decrypt(ref text); ReportStatus(status); if (HaspStatus.StatusOk == status) { Verbose("Decrypted string: \"" + text + "\""); } } Verbose(""); }