gpt4 book ai didi

c# - WinRT 中的文件加密

转载 作者:行者123 更新时间:2023-12-02 22:43:19 25 4
gpt4 key购买 nike

我目前正在开发需要文件加密的 Metro 应用程序 (C#/XAML)。在 Winforms 和 WPF 中,我只需要写

System.IO.File.Encrypt("file.txt");

如何在 WinRT 中做同样的事情?

最佳答案

首先,我绝不会使用 System.IO.File.Encrypt 来加密文件。
其次,我会查看以下文档:Windows Runtime API
第三,我会使用类似的方法加密文件描述 herehere

public MainWindow()
{
InitializeComponent();

byte[] encryptedPassword;

// Create a new instance of the RijndaelManaged
// class. This generates a new key and initialization
// vector (IV).
using (var algorithm = new RijndaelManaged())
{
algorithm.KeySize = 256;
algorithm.BlockSize = 128;

// Encrypt the string to an array of bytes.
encryptedPassword = Cryptology.EncryptStringToBytes("Password",
algorithm.Key, algorithm.IV);
}

string chars = encryptedPassword.Aggregate(string.Empty,
(current, b) => current + b.ToString());

Cryptology.EncryptFile(@"C:\Users\Ira\Downloads\test.txt", @"C:\Users\Ira\Downloads\encrypted_test.txt", chars);

Cryptology.DecryptFile(@"C:\Users\Ira\Downloads\encrypted_test.txt", @"C:\Users\Ira\Downloads\unencyrpted_test.txt", chars);
}

关于c# - WinRT 中的文件加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10435347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com