private async Task DecryptDataBaseAsync(string password) { FileEncrypter encrypter = new FileEncrypter(new AESEncrypter(password)); if (File.Exists(RuntimeStorageFileName)) { File.Delete(RuntimeStorageFileName); await Task.Delay(TimeSpan.FromMilliseconds(100)); // 等待100毫秒,确定文件处于空闲状态 } //解密储存库 lock (_storageFileLocker) { File.Copy(StorageFile, RuntimeStorageFileName); encrypter.Decrypt(RuntimeStorageFileName); Thread.Sleep(TimeSpan.FromMilliseconds(100)); // 等待100毫秒,确定文件处于空闲状态 File.SetAttributes(RuntimeStorageFileName, FileAttributes.Hidden); } }
public void TestImageDecryption() { Aes provider = FileEncrypter.GetProvider(KEY); { byte[] clean = File.ReadAllBytes("Embedded/application-sidebar-list.nopng"); byte [] content = FileEncrypter.Encrypt(clean, provider); byte[] output = FileEncrypter.Decrypt(content, provider); File.WriteAllBytes("dummy2.png", output); } { byte [] content = File.ReadAllBytes("dummy.png"); byte[] output = FileEncrypter.Decrypt(content, provider); File.WriteAllBytes("dummy3.png", output); } }