1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Globalization;
- using System.IO;
- using System.Reflection;
- using System.Text;
- namespace Microsoft.Samples.AppUpdater
- {
- public class KeyValidator : MarshalByRefObject
- {
- public bool Validate(string assemblyLocation, byte[][] keyList, string[] ExceptionList)
- {
- try
- {
- if (IsException(assemblyLocation, ExceptionList))
- {
- return true;
- }
- Assembly assembly = Assembly.LoadFrom(assemblyLocation);
- return CompareKeys(assembly.GetName().GetPublicKey(), keyList);
- }
- catch (Exception)
- {
- return false;
- }
- }
- public static bool IsException(string FilePath, string[] ExceptionList)
- {
- if (ExceptionList == null)
- {
- return false;
- }
- foreach (string text in ExceptionList)
- {
- if (Path.GetFileName(FilePath).ToLower(new CultureInfo("en-US")) == text.ToLower(new CultureInfo("en-US")))
- {
- return true;
- }
- }
- return false;
- }
- public static bool CompareKeys(byte[] assemblyKey, byte[][] validKeys)
- {
- try
- {
- ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
- foreach (byte[] bytes in validKeys)
- {
- if (aSCIIEncoding.GetString(bytes) == aSCIIEncoding.GetString(assemblyKey))
- {
- return true;
- }
- }
- return false;
- }
- catch (Exception)
- {
- return false;
- }
- }
- }
- }
|