【问题标题】:Hash and Salt string in Windows Store AppWindows Store 应用程序中的哈希和盐字符串
【发布时间】:2015-07-02 08:34:35
【问题描述】:

我一直在尝试对必须保存在设备上的密码进行哈希和加盐。这是我一直在使用的代码,但在 Windows Store Framework 中找不到 System.Security.Cryptography 和 RNGCryptoServiceProvider。

public static string CreateSalt(int size)
{
    var rng = new RNGCryptoServiceProvider();
    var buff = new byte[size];
    rng.GetBytes(buff);
    return Convert.ToBase64String(buff);
}

public static string GenerateSHA256Hash(string input, string salt)
{
    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
    SHA1Managed sha = new SHA1Managed();
    byte[] hash = sha.ComputeHash(bytes);

    return Convert.ToBase64String(hash);
}

有人对如何在 Windows 应用商店应用程序上执行此操作有建议吗? 谢谢

【问题讨论】:

  • 为什么windows商店应用哈希密码?这不是客户端应用程序的工作
  • 我需要在本地保存密码,我不希望将其保存在纯字符串中

标签: c# hash windows-store-apps salt sha


【解决方案1】:

有一个替代使用 RNGCryptoServiceProvider

var buffer = CryptographicBuffer.GenerateRandom(saltlength);
var string = CryptographicBuffer.EncodeToBase64String(buffer)

Windows.Security.Cryptography 是用于 Windows 商店应用的 System.Security.Cryptography 的替代品。

【讨论】:

    猜你喜欢
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 2013-08-16
    • 2011-05-27
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    相关资源
    最近更新 更多