public void TestKeyFileCreation() { var keyFile = new KeyFile("C:/Persistence", "Test"); var objectIdA = new ObjectId(); var objectIdB = new ObjectId(); var objectIdC = new ObjectId(); keyFile.Update(objectIdA, 100, 1000); keyFile.Update(objectIdB, 200, 2000); keyFile.Update(objectIdC, 300, 3000); int offset = 0; int dataSizeBytes = 0; Assert.IsTrue(keyFile.Get(objectIdA, ref offset, ref dataSizeBytes)); Assert.IsTrue(offset == 100); Assert.IsTrue(dataSizeBytes == 1000); Assert.IsTrue(keyFile.Get(objectIdB, ref offset, ref dataSizeBytes)); Assert.IsTrue(offset == 200); Assert.IsTrue(dataSizeBytes == 2000); Assert.IsTrue(keyFile.Get(objectIdC, ref offset, ref dataSizeBytes)); Assert.IsTrue(offset == 300); Assert.IsTrue(dataSizeBytes == 3000); keyFile.Save(); }
public void KeyLocationExistsTest() { var target = new KeyFile(); Assert.IsTrue(target.KeyLocationExists("Readme.txt")); Assert.IsFalse(target.KeyLocationExists("DontReadme.txt")); }
private void BMSChanged() { try { statusAssign = Status.GetNeutralPos; LargeTab.SelectedIndex = 0; // Read Theater List TheaterList.PopulateAndSave(appReg, Dropdown_TheaterList); // Read BMS-FULL.key string fname = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getKeyFileName(); string fnameauto = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getAutoKeyFileName(); if (!File.Exists(fnameauto)) { File.Copy(fname, fnameauto); } keyFile = new KeyFile(fnameauto, appReg); // Write Data Grid WriteDataGrid(); } catch (Exception ex) { Diagnostics.WriteLogFile(ex); Close(); } }
private void LoadKeyFile(string keyFileName) { if (string.IsNullOrEmpty(keyFileName)) { throw new ArgumentNullException("keyFileName"); } var file = new FileInfo(keyFileName); if (!file.Exists) { throw new FileNotFoundException(keyFileName); } var oldViewerState = (ViewerState)_viewerState.Clone(); try { _viewerState.Filename = keyFileName; _viewerState.KeyFile = KeyFile.Load(keyFileName); ParseKeyFile(); } catch (Exception e) { MessageBox.Show(string.Format("An error occurred while loading the file.\n\n {0}", e.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); _viewerState = oldViewerState; } }
public static KeyFile GetCurrentKeyFile() { KeyFile toReturn = null; string falconKeyFilePath = null; using (var reader = new F4SharedMem.Reader()) { falconKeyFilePath = reader.GetCurrentData()?.StringData?.data?.Where(x => x.strId == (uint)F4SharedMem.Headers.StringIdentifier.KeyFile).First().value; } if (string.IsNullOrEmpty(falconKeyFilePath)) { return(null); } var keyFileInfo = new FileInfo(falconKeyFilePath); if (!keyFileInfo.Exists) { return(null); } try { toReturn = KeyFile.Load(falconKeyFilePath); } catch (IOException e) { Log.Error(e.Message, e); } return(toReturn); }
protected FlickrManager LoadToken() { var mgr = new FlickrManager(); AccessToken token; try { using (var stream = KeyFile.OpenRead()) { token = stream.Load <AccessToken>(); } } catch (Exception ex) { throw new InvalidOperationException($"Error loading token '{KeyFile.FullName}'. {ex.Message}"); } try { mgr.ApplyToken(token); } catch (Exception ex) { throw new InvalidOperationException($"Supplied token is invalid. {ex.Message}"); } return(mgr); }
/// <summary> /// Creates and saves stored keyfile in appdata based on current filename. /// </summary> /// <returns>New keyfile saved to disk.</returns> public static async Task <KeyFile> CreateStoredKeyFile(string saveLocation) { KeyFile key = new KeyFile(true); await FileManager.SaveFileAsync(saveLocation, FileManager.Serialize(key), true); return(key); }
private void LoadCurrentKeyFile() { if (!Settings.Default.RunAsClient) { _keyFile = KeyFileUtils.GetCurrentKeyFile(); } }
void OkButtonClick(object sender, EventArgs e) { KeyFile = KeyFile.Trim(); if (KeyFile.Length == 0) { MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.EnterKeyName}"); return; } bool usePassword = Get <CheckBox>("usePassword").Checked; if (usePassword) { if (!CheckPassword(ControlDictionary["passwordTextBox"], ControlDictionary["confirmPasswordTextBox"])) { return; } MessageService.ShowMessage("Creating a key file with a password is currently not supported."); return; } if (!KeyFile.EndsWith(".snk") && !KeyFile.EndsWith(".pfx")) { KeyFile += ".snk"; } if (CreateKey(Path.Combine(baseDirectory, KeyFile))) { this.DialogResult = DialogResult.OK; Close(); } }
private static void CreateKeyFile(string path, out string encrKey, out string signKey) { KeyProtection.CreateKeys(out encrKey, out signKey); var keys = new KeyFile { encryptKey = encrKey, signKey = signKey }; var json = Newtonsoft.Json.JsonConvert.SerializeObject(keys); File.WriteAllText(path, json); }
public void PutKeyBlankLocationAsyncTest() { TestUtilities.AsyncTestWrapper(TestContext, () => { var target = new KeyFile(); target.PutKeyAsync(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, " \t").Wait(); }); }
public void GetKeyBlankLocationAsyncTest() { TestUtilities.AsyncTestWrapper(TestContext, () => { var target = new KeyFile(); target.GetKeyAsync(" \t").Wait(); }); }
private void OnFileDownloaded(MetaListItemInfo item, string path, byte[] bytes) { var dispatcher = Dispatcher; try { using (var buffer = new MemoryStream(bytes)) { if (string.IsNullOrEmpty(_folder)) { if (!DatabaseVerifier.Verify(dispatcher, buffer)) { return; } var name = item.Title.RemoveKdbx(); var storage = new DatabaseInfo(); storage.SetDatabase(buffer, new DatabaseDetails { Url = path, Name = name, Modified = item.Modified, Type = SourceTypes.Synchronizable, Source = DatabaseUpdater.ONEDRIVE_UPDATER, }); dispatcher.BeginInvoke( this.BackToDBs); } else { var hash = KeyFile.GetKey(buffer); if (hash == null) { dispatcher.BeginInvoke(() => MessageBox.Show( Properties.Resources.InvalidKeyFile, Properties.Resources.KeyFileTitle, MessageBoxButton.OK)); return; } new DatabaseInfo(_folder) .SetKeyFile(hash); dispatcher.BeginInvoke( this.BackToDBPassword); } } } finally { dispatcher.BeginInvoke(() => progBusy.IsBusy = false); } }
private void GenerateKeyAndSend(String Name, String Organisation, String EmailAddress, bool SendMail) { //Opbouwen compleet bericht String MessageToEncrypt = "<xml><applicatie name=\"Copying Machine\" version=\"2.00\"/>"; MessageToEncrypt += "<user name=\""; MessageToEncrypt += Name; MessageToEncrypt += "\" organisation=\""; MessageToEncrypt += Organisation; MessageToEncrypt += "\" id=\""; MessageToEncrypt += System.DateTime.Now.ToShortDateString() + System.DateTime.Now.ToShortTimeString(); MessageToEncrypt += "\" emailaddress=\""; MessageToEncrypt += EmailAddress; MessageToEncrypt += "\"/></xml>"; System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); Byte[] bytes = encoding.GetBytes(MessageToEncrypt); byte[] dataToEncrypt = new byte[1 + bytes.Length]; //Add the checksum to the xml int iChecksum = 0; for (int i = 0; i < MessageToEncrypt.Length; i++) { iChecksum = iChecksum + bytes[i]; dataToEncrypt[i + 1] = bytes[i]; } iChecksum = (iChecksum & 0x07); iChecksum = (iChecksum << 5) & 0xFF; iChecksum = iChecksum | 0x20; dataToEncrypt[0] = Convert.ToByte(iChecksum); //Construct the name of the keyfile to be generated String KeyFile; KeyFile = "Keys\\copymach_"; KeyFile += Name.ToLower(); KeyFile += ".cmk"; KeyFile = KeyFile.Replace(" ", ""); if (!Directory.Exists("Keys")) { Directory.CreateDirectory("Keys"); } //Create the key Key(KeyFile, dataToEncrypt, dataToEncrypt.Length); //Send e-mail if (SendMail) { MailKey(KeyFile, EmailAddress); } }
public void DeleteKeyLocationNonExistentTest() { var target = new KeyFile(); Assert.IsFalse(File.Exists("foo.key")); target.DeleteKeyLocation("foo.key"); Assert.IsFalse(File.Exists("foo.key")); }
public void PutKeyNullKeyAsyncTest() { TestUtilities.AsyncTestWrapper(TestContext, () => { var target = new KeyFile(); target.PutKeyAsync(null, "foo.key").Wait(); Assert.IsFalse(File.Exists("foo.key")); }); }
private static IntPtr KeyFileClone(ref KeyFile keyFile) { if (Environment.Is64BitProcess) { return(KeyFileClone_64(ref keyFile)); } else { return(KeyFileClone_32(ref keyFile)); } }
private void OnFileDownloaded(byte[] file, string path, string title, string modified) { var dispatcher = Dispatcher; try { using (var buffer = new MemoryStream(file)) { if (string.IsNullOrEmpty(_folder)) { if (!DatabaseVerifier.Verify(dispatcher, buffer)) { return; } var storage = new DatabaseInfo(); storage.SetDatabase(buffer, new DatabaseDetails { Modified = modified, Name = title.RemoveKdbx(), Url = _client.GetUrl(path), Type = SourceTypes.Synchronizable, Source = DatabaseUpdater.WEBDAV_UPDATER, }); } else { var hash = KeyFile.GetKey(buffer); if (hash == null) { dispatcher.BeginInvoke(() => MessageBox.Show( Properties.Resources.InvalidKeyFile, Properties.Resources.KeyFileTitle, MessageBoxButton.OK)); return; } new DatabaseInfo(_folder) .SetKeyFile(hash); } } dispatcher.BeginInvoke( this.BackToDBs); } finally { dispatcher.BeginInvoke(() => progBusy.IsBusy = false); } }
public static KeyBinding FindKeyBinding(string callback) { if (_keyFile == null) { _keyFile = GetCurrentKeyFile(); } if (_keyFile == null) { return(null); } return(_keyFile.GetBindingForCallback(callback) as KeyBinding); }
public void PutKeyTest() { File.Delete("foo.key"); var target = new KeyFile(); target.PutKey(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "foo.key"); Assert.IsTrue(File.Exists("foo.key")); File.Delete("foo.key"); }
/// <summary> /// Load a stored keyfile from disk at given location. /// </summary> /// <param name="saveLocation">File location on disk.</param> /// <returns>Keyfile from disk, or if not found, null.</returns> public static async Task <KeyFile> LoadStoredKeyFile(string saveLocation) { byte[] data = await FileManager.OpenFile(saveLocation); KeyFile key = null; if (data != null) { key = FileManager.Deserialize <KeyFile>(data); } return(key); }
public void TestKeyLookup() { var keyFile = new KeyFile("C:/Persistence", "Test"); var objectId = new ObjectId(); var deepCopiedObjectId = new ObjectId(objectId.AsInt()); keyFile.Update(objectId, 100, 1000); int offset = 0; int dataSizeBytes = 0; Assert.IsTrue(keyFile.Get(objectId, ref offset, ref dataSizeBytes), "Original"); Assert.IsTrue(keyFile.Get(deepCopiedObjectId, ref offset, ref dataSizeBytes), "Deep copy"); }
public KeyMappingWindow(MainWindow mainWindow, KeyAssgn SelectedCallback, KeyFile keyFile, DeviceControl deviceControl) { InitializeComponent(); this.mainWindow = mainWindow; CallbackName.Content = SelectedCallback.GetKeyDescription(); Select_PinkyShift.IsChecked = true; Select_DX_Release.IsChecked = true; this.SelectedCallback = SelectedCallback; this.keyFile = keyFile; Reset(); }
public void GetKeyTest() { File.Delete("foo.key"); var target = new KeyFile(); target.PutKey(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "foo.key"); Assert.IsTrue(File.Exists("foo.key")); var key = target.GetKey("foo.key"); Assert.IsNotNull(key); Assert.IsTrue(key.SequenceEqual(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })); File.Delete("foo.key"); }
public GMpiFileInfo(string mediaPlayerId) { try { mpi_file = new KeyFile(); mpi_file.SetListSeparator(Separator); string full_path; mpi_file.LoadFromDirs(String.Format("{0}.mpi", mediaPlayerId), new string [] { "/usr/share/media-player-info", "/usr/local/share/media-player-info" }, out full_path, KeyFileFlags.None); } catch (GLib.GException) { Hyena.Log.WarningFormat("Failed to load media-player-info file for {0}", mediaPlayerId); } LoadProperties(); }
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) { InitialLocalValues(); if (args.Files != null && args.Files.Count > 0) { var action = (args.ContinuationData["Action"] as string); StorageFile file; switch (action) { case KdbxFormat: { file = args.Files[0]; if (file.Name.EndsWith(KdbxFormat, StringComparison.OrdinalIgnoreCase)) { var info = new DatabaseInfo(); var test = await file.OpenReadAsync(); info.SetDatabase(test.AsStream(), new DatabaseDetails { Source = "FileSystem", Name = file.Name.RemoveKdbx(), Type = SourceTypes.OneTime, }); this.NavigateTo <MainPage>(); } } break; case KeyFormat: file = args.Files[0]; if (file.Name.EndsWith(KeyFormat, StringComparison.OrdinalIgnoreCase)) { var test = await file.OpenReadAsync(); (new DatabaseInfo(_folder)).SetKeyFile(KeyFile.GetKey(test.AsStream())); NavigationService.GoBack(); // this.NavigateTo<MainPage>(); } break; } } }
public KeyMappingWindow(KeyAssgn SelectedCallback, KeyFile keyFile, DeviceControl deviceControl) { InitializeComponent(); CallbackName.Content = SelectedCallback.GetKeyDescription(); Select_PinkyShift.IsChecked = true; Select_DX_Release.IsChecked = true; this.SelectedCallback = SelectedCallback; this.keyFile = keyFile; this.deviceControl = deviceControl; neutralButtons = new NeutralButtons[deviceControl.devList.Count]; tmpJoyStick = new JoyAssgn[deviceControl.devList.Count]; for (int i = 0; i < deviceControl.devList.Count; i++) { tmpJoyStick[i] = deviceControl.joyAssign[i].Clone(); } tmpCallback = this.SelectedCallback.Clone(); }
/// <summary> /// Execute setting override. /// </summary> /// <param name="inGameAxis"></param> /// <param name="deviceControl"></param> /// <param name="keyFile"></param> /// <param name="visualAcuity"></param> public void Execute(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile) { if (!Directory.Exists(appReg.GetInstallDir() + "/User/Config/Backup/")) { Directory.CreateDirectory(appReg.GetInstallDir() + "/User/Config/Backup/"); } MainWindow.deviceControl.SortDevice(); SaveAxisMapping(inGameAxis, deviceControl); SaveJoystickCal(inGameAxis, deviceControl); SaveDeviceSorting(deviceControl); SaveConfigfile(inGameAxis, deviceControl); SaveKeyMapping(inGameAxis, deviceControl, keyFile); //SavePlcLbk(); SavePop(); SaveWindowConfig(); SaveJoyAssignStatus(deviceControl); }
public bool InitTest() { string path = "C:\\Users\\dewints\\Downloads\\fdm.key"; if (!KeyFile.TryLoadFromFile(path, "DEMO" /* TODO use your own passphase */, out k)) { Debug.WriteLine("Unable to load the key file \"" + path + "\"."); return(false); } c = FDMClient.CreateClient(k, Languages.English); if (c == null) { Debug.WriteLine("Unable to create the FDM client."); return(false); } return(true); }
public void GetKeyAsyncTest() { TestUtilities.AsyncTestWrapper(TestContext, () => { File.Delete("foo.key"); var target = new KeyFile(); target.PutKeyAsync(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "foo.key").Wait(); Assert.IsTrue(File.Exists("foo.key")); var key = target.GetKeyAsync("foo.key").Result; Assert.IsNotNull(key); Assert.IsTrue(key.SequenceEqual(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })); File.Delete("foo.key"); }); }
public unsafe bool LoadFromDirs(string file, string search_dirs, string full_path, KeyFile.Flags flags) { IntPtr native_file = GLib.Marshaller.StringToPtrGStrdup (file); IntPtr native_search_dirs = GLib.Marshaller.StringToPtrGStrdup (search_dirs); IntPtr error = IntPtr.Zero; bool raw_ret = g_key_file_load_from_dirs(Handle, native_file, native_search_dirs, GLib.Marshaller.StringToPtrGStrdup(full_path), (int) flags, out error); bool ret = raw_ret; GLib.Marshaller.Free (native_file); GLib.Marshaller.Free (native_search_dirs); if (error != IntPtr.Zero) throw new GLib.GException (error); return ret; }
/* * GKeyFile.custom * * Author(s): * Stephane Delcroix ([email protected]) * * Copyright (c) 2008 Novell, Inc. * * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ public GKeyFile (string file, KeyFile.Flags flags) : this () { LoadFromFile (file, flags); }
/// <summary> /// Use this to load a key file /// </summary> /// <param name="path">Path to key file</param> public bool LoadKey(string path) { //does file exist if(!File.Exists(path)) { return false; } //maby the json in the file is broekn? try { _kf = JsonConvert.DeserializeObject<KeyFile>(File.ReadAllText(path)); } catch { return false; } //well every thing worked out. return true; }
private static IntPtr KeyFileClone(ref KeyFile keyFile) { if (Environment.Is64BitProcess) { return KeyFileClone_64(ref keyFile); } else { return KeyFileClone_32(ref keyFile); } }
private static extern IntPtr KeyFileClone_64(ref KeyFile keyFile);
public unsafe bool LoadFromFile(string file, KeyFile.Flags flags) { IntPtr native_file = GLib.Marshaller.StringToPtrGStrdup (file); IntPtr error = IntPtr.Zero; bool raw_ret = g_key_file_load_from_file(Handle, native_file, (int) flags, out error); bool ret = raw_ret; GLib.Marshaller.Free (native_file); if (error != IntPtr.Zero) throw new GLib.GException (error); return ret; }
public unsafe bool LoadFromData(string data, KeyFile.Flags flags) { IntPtr native_data = GLib.Marshaller.StringToPtrGStrdup (data); IntPtr error = IntPtr.Zero; bool raw_ret = g_key_file_load_from_data(Handle, native_data, new UIntPtr ((ulong) System.Text.Encoding.UTF8.GetByteCount (data)), (int) flags, out error); bool ret = raw_ret; GLib.Marshaller.Free (native_data); if (error != IntPtr.Zero) throw new GLib.GException (error); return ret; }
public static bool KeyFilesApply(ref Password password, IEnumerable<string> keyfiles) { // prepare a list in native memory with all keyfiles KeyFile keyfileStruct = new KeyFile(); IntPtr firstKeyfilePtr = IntPtr.Zero; foreach (string keyfile in keyfiles) { keyfileStruct.FileName = keyfile; IntPtr keyfilePtr = KeyFileClone(ref keyfileStruct); firstKeyfilePtr = KeyFileAdd(firstKeyfilePtr, keyfilePtr); } // apply the keyfiles to the password bool retval = KeyFilesApply(ref password, firstKeyfilePtr); // free the memory used by the keyfiles KeyFileRemoveAll(ref firstKeyfilePtr); return retval; }
public void SaveKey(string path, KeyFile f) { //save the file File.WriteAllText(path, JsonConvert.SerializeObject(f)); }