【问题标题】:Using DESCryptoServiceProvider in Universal Windows Platform (UWP) app在通用 Windows 平台 (UWP) 应用程序中使用 DESCryptoServiceProvider
【发布时间】:2016-04-25 20:31:20
【问题描述】:

我有一个与我的 Web 服务通信的 UWP 应用,为了使用某些方法,我的应用必须加密参数。 对于解密,我们在

中使用了DESCryptoServiceProvider and CryptoStream
System.Security.Cryptography

但是UWP没有System.Security.Cryptography,Windows.Security.Cryptography不包含DESCryptoServiceProvider and CryptoStream!!!

请帮帮我,谢谢。

【问题讨论】:

    标签: uwp des


    【解决方案1】:

    在通用 Windows 应用中,您必须使用 CryptographicEngine 进行加密和解密操作。

    对于您的解密用例,您将使用 DecryptAsync 方法,除了加密数据和 IV 之外,该方法还需要一个密钥来执行操作。

    您需要的密钥将由SymmetricKeyAlgorithmProvider 类创建。因此,通过打开desired algorithm 初始化一个新实例并创建密钥。

    例如:

    // Static method call, "SymmetricAlgorithmNames" has several DES algorithms,
    // so choose the correct one
    var provider = SymmetricKeyAlgorithmProvider
                       .OpenAlgorithm(SymmetricAlgorithmNames.DesEcbPkcs7);
    var key = provider.CreateSymmetricKey(myKeyMaterial);
    

    【讨论】:

    • 您知道如何使用现有密钥而不是创建新密钥吗? API 似乎没有提供“导入”现有密钥以用于对称算法的方法。
    • @disklosr 方法同上,只是myKeyMaterial不同。这与您使用密码作为密钥材料的方式相同。您最终将得到大约 230 行代码,在两者之间使用 IBufferCryptographicEngine.DeriveKeyMaterial。这不是很直观,是的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 2016-06-03
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多