/// <summary> /// Saves the authentications into the specified file /// </summary> /// <param name="authenticationModels"></param> internal static void Save(BindingList <AuthenticationModel> authenticationModels) { var encryptedJsonString = CipherExtensions.EncryptString(JsonConvert.SerializeObject(authenticationModels), _authenticationKey); Bitmap bitmap; using (var stream = new FileStream(ImageFilePath, FileMode.Open, FileAccess.Read)) { bitmap = SteganographyExtensions.CreateNonIndexedImage(Image.FromStream(stream)); } var encryptedImage = SteganographyExtensions.SaveString(encryptedJsonString, bitmap); encryptedImage.Save(ImageFilePath); }
/// <summary> /// Loads the authentication from a file /// </summary> /// <returns></returns> internal static BindingList <AuthenticationModel> Load() { var authenticationModels = new BindingList <AuthenticationModel>(); if (!IsAuthenticatedFile()) { return(authenticationModels); } Bitmap bitmap; using (var stream = new FileStream(ImageFilePath, FileMode.Open, FileAccess.Read)) { bitmap = SteganographyExtensions.CreateNonIndexedImage(Image.FromStream(stream)); } var encryptedJsonString = SteganographyExtensions.GetString(new Bitmap(bitmap)); var decryptedJsonString = CipherExtensions.DecryptString(encryptedJsonString, _authenticationKey); authenticationModels = JsonConvert.DeserializeObject <BindingList <AuthenticationModel> >(decryptedJsonString); return(authenticationModels); }