Ejemplo n.º 1
0
        private static TrialData CheckRegistryData(String regBranch, String regKey, String regParam, String keyFileName)
        {
            object obj;

            using (var rk = Registry.CurrentUser.CreateSubKey(String.Format("{0}{1}{2}",
                                                                            regBranch,
                                                                            regBranch.EndsWith("\\", StringComparison.Ordinal) ? String.Empty : "\\",
                                                                            regKey)))
            {
                obj = rk.GetValue(regParam);
            }
            if (obj == null)
            {
                return new TrialData(DateTime.Now)
                       {
                           LastStart = DateTime.Now
                       }
            }
            ;
            byte[] encryptedObject = obj as byte[];
            if (encryptedObject == null)
            {
                throw new CryptographicException("Unexpected data type");
            }
            return((TrialData)ClmEncryptor.DecryptObject(keyFileName, encryptedObject));
        }
Ejemplo n.º 2
0
        private static void SaveToFile(TrialData data, String fileName, String keyFileName)
        {
            var encryptedObject = ClmEncryptor.EncryptObject(keyFileName, data);

            using (var f = File.Open(fileName, FileMode.Create, FileAccess.Write))
            {
                f.Write(encryptedObject, 0, encryptedObject.Length);
            }
        }
Ejemplo n.º 3
0
 private static void SaveToRegistry(TrialData data, String regBranch, String regKey, String regParam, String keyFileName)
 {
     byte[] encryptedObject = ClmEncryptor.EncryptObject(keyFileName, data);
     using (var rk = Registry.CurrentUser.CreateSubKey(String.Format("{0}{1}{2}",
                                                                     regBranch,
                                                                     regBranch.EndsWith("\\", StringComparison.Ordinal) ? String.Empty : "\\",
                                                                     regKey)))
     {
         rk.SetValue(regParam, encryptedObject, RegistryValueKind.Binary);
     }
 }
Ejemplo n.º 4
0
 private static TrialData CheckFileData(String fileName, String keyFileName)
 {
     if (!File.Exists(fileName))
     {
         return new TrialData(DateTime.Now)
                {
                    LastStart = DateTime.Now
                }
     }
     ;
     byte[] buffer = new byte[1024];
     using (MemoryStream mstr = new MemoryStream())
     {
         using (var f = File.Open(fileName, FileMode.Open, FileAccess.Read))
         {
             int n;
             while ((n = f.Read(buffer, 0, buffer.Length)) > 0)
             {
                 mstr.Write(buffer, 0, n);
             }
         }
         return((TrialData)ClmEncryptor.DecryptObject(keyFileName, mstr.ToArray()));
     }
 }