gpt4 book ai didi

c# - 在 Windows Phone 上进行加密

转载 作者:太空宇宙 更新时间:2023-11-03 13:01:06 24 4
gpt4 key购买 nike

我编写了一些代码,允许我在 C# 中进行加密 - 主要使用 System.Security.Cryptography 中的 AesManaged()SHA256Managed()

用例是该工具需要能够提取一段加密的数据,对其进行解密,将其显示给用户,允许再次编辑和加密,然后再将其发回。

我希望能够在 Windows Phone 上做类似的事情,但似乎命名空间在手机上不可用。

那么我现在有什么选择呢?它会在 Windows Phone 10 上可用吗?似乎在手机应用程序中进行加密是一项相对常见的任务?

编辑:添加了关于应用应该做什么的信息

最佳答案

你想用密码学做什么?因为如果您只需要存储一些用户凭据,最好的方法是使用 PasswordVault

此处引用 MSDN https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.security.credentials.passwordvault.aspx

我在这里做了一个例子 http://depblog.weblogs.us/2014/11/20/migrating-from-sl8-0-protectdata-to-rt8-1-passwordvault/

添加了一些关于如何在 Vault 中添加和删除条目的示例代码(博客文章中有更多详细信息)

public async Task AddAccount(Account accountToAdd)
{
//Reinitialize the vault to see if the given account is already available
await this.InitializeSettingsService();
Account accountFromVault = this.Accounts.FirstOrDefault(item => item.UserName.Equals(accountToAdd.UserName, StringComparison.OrdinalIgnoreCase));

if(accountFromVault == null)
_vault.Add(new PasswordCredential(Constants.VAULTRESOURCENAME, accountToAdd.UserName, accountToAdd.Password));

if (accountFromVault != null && !accountFromVault.Password.Equals(accountToAdd.Password, StringComparison.Ordinal))
{
_vault.Remove(new PasswordCredential(Constants.VAULTRESOURCENAME, accountFromVault.UserName, accountFromVault.Password));
_vault.Add(new PasswordCredential(Constants.VAULTRESOURCENAME, accountToAdd.UserName, accountToAdd.Password));
}

Account accountFromMemory = this.Accounts.FirstOrDefault(item => item.UserName.Equals(accountToAdd.UserName, StringComparison.OrdinalIgnoreCase));
if (accountFromMemory != null)
{
if (!accountFromMemory.Password.Equals(accountToAdd.Password, StringComparison.OrdinalIgnoreCase))
{
this.Accounts.Remove(accountFromMemory);
this.Accounts.Add(accountToAdd);
}
}
else
this.Accounts.Add(accountToAdd);
}

public async Task RemoveAccount(Account accountToRemove)
{
//Reinitialize the vault to see if the given account is already available
await this.InitializeSettingsService();
Account accountFromVault = this.Accounts.FirstOrDefault(item => item.UserName.Equals(accountToRemove.UserName, StringComparison.OrdinalIgnoreCase));

if (accountFromVault != null)
_vault.Remove(new PasswordCredential(Constants.VAULTRESOURCENAME, accountToRemove.UserName, accountToRemove.Password));

Account accountFromMemory = this.Accounts.FirstOrDefault(item => item.UserName.Equals(accountToRemove.UserName, StringComparison.OrdinalIgnoreCase));
if (accountFromMemory != null)
this.Accounts.Remove(accountFromMemory);
}

关于c# - 在 Windows Phone 上进行加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32266150/

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