public void FileHashingShouldWork() { //string test = provider.HashFile(Directory.GetCurrentDirectory() + "\\FileHashingTestFile.txt"); string test = provider.HashFile(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\FileHashingTestFile.txt"); Assert.IsNotNull(test); Assert.AreEqual(hashValue, test); }
private void PrintAttribute() { IHashingProvider hashingProvider = ObjectLocator.GetInstance <IHashingProvider>(); IEncodingService encodingService = ObjectLocator.GetInstance <IEncodingService>(); string dllCheckHash = encodingService.Encode(hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll")); string publicKey = encodingService.Encode(UIContext.License.KeyPair.PublicKey); if (rdoCodeTypeCSharp.IsChecked.HasValue && rdoCodeTypeCSharp.IsChecked.Value) { txtAttribute.Text = string.Format("[assembly: License(\"{0}\",\"{1}\")]", publicKey, dllCheckHash); } else { txtAttribute.Text = string.Format("<Assembly: License(\"{0}\",\"{1}\")>", publicKey, dllCheckHash); } txtParam1.Text = publicKey; txtParam2.Text = dllCheckHash; }
/// <summary> /// This function needs to be one of the first things calls to ensure that /// the licensing assembly is valid /// </summary> private void VerifyLicensingAssembly() { string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); path = path.Replace("file:\\", ""); //string currentFileHash = hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\WaveTech.Scutex.Licensing.dll"); string currentFileHash = hashingProvider.HashFile(path + "\\WaveTech.Scutex.Licensing.dll"); #if (!DEBUG) // This code is disabled during dev (in debug mode) because the assembly // hash will keep on changing, and this will kill the application and any tests. if (currentFileHash != dllCheck) { MessageBox.Show("Scutex Licensing\r\n\r\n" + "If you are getting this error message Scutex Licensing was unable to \r\n" + "verify the licensing DLL. This means that the DLL might have been\r\n" + "corrupted or might have been tampered with.\r\n\r\n" + "To fix this issue you need to either replace the DLL file with the correct file or regenerate the licensing data file from the Scutex Licensing Manager.", "Scutex Licensing", MessageBoxButton.OK, MessageBoxImage.Error); //Environment.Exit(1001); throw new ScutexAuditException(); } #endif //assemblyVerified = true; }
private void btnGetCCWFile_Click(object sender, RoutedEventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.FileName = "ScutexLicensingCCW.dll"; dialog.DefaultExt = ".dll"; dialog.Filter = "DLL Files (.dll)|*.dll"; dialog.ShowDialog(); if (!String.IsNullOrEmpty(dialog.FileName)) { string assemblyPath = Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll"; IHashingProvider hashingProvider = ObjectLocator.GetInstance <IHashingProvider>(); IEncodingService encodingService = ObjectLocator.GetInstance <IEncodingService>(); string dllCheckHash = encodingService.Encode(hashingProvider.HashFile(assemblyPath)); string publicKey = encodingService.Encode(UIContext.License.KeyPair.PublicKey); IComApiWrappingService comApiWrappingService = ObjectLocator.GetInstance <IComApiWrappingService>(); comApiWrappingService.CreateComWrapper(dialog.FileName, assemblyPath, publicKey, dllCheckHash); } }
private static void Demo(object sender, ExecutedRoutedEventArgs e) { if (UIContext.License != null) { DemoHostHelper helper = new DemoHostHelper(); helper.CleanPreviousHost(); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); path = path.Replace("file:\\", ""); ClientLicense cl = new ClientLicense(UIContext.License); IClientLicenseService clientLicenseService = ObjectLocator.GetInstance <IClientLicenseService>(); clientLicenseService.SaveClientLicense(cl, path + @"\sxu.dll"); IHashingProvider hashingProvider = ObjectLocator.GetInstance <IHashingProvider>(); IEncodingService encodingService = ObjectLocator.GetInstance <IEncodingService>(); string dllCheckHash = encodingService.Encode(hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll")); string publicKey = encodingService.Encode(UIContext.License.KeyPair.PublicKey); try { File.Copy(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll", Directory.GetCurrentDirectory() + "\\WaveTech.Scutex.Licensing.dll"); } catch { } helper.CreateAssembly(publicKey, dllCheckHash); helper.ExecuteAssembly(); helper = null; } else { MessageBox.Show("You must have an open licensing project to view the demo trial form."); } }