代码之家  ›  专栏  ›  技术社区  ›  Ian Boyd

Windows是否使用密码进行身份验证加密(c.f.CryptProtectData)

  •  0
  • Ian Boyd  · 技术社区  · 7 年前

    Windows是否提供了一个高级的、经过测试的、受支持的功能来使用对称密钥执行经过身份验证的加密?

    背景

    CryptProtectData API,我们可以将其封装在一个易于使用的函数中:

    public Byte[] ProtectBytes(Byte[] plaintext)
    {
       //...
    }
    

    ProtectBytes 比你可以很容易地使用它更重要的是:

    • System
    • 把加密的斑点还给我

    他回来了 斑点 documentation

    为完整起见,下面是 保护字节 使用 Crypt API

    public Byte[] ProtectBytes(Byte[] plaintext)
    {
       //Setup our n-byte plaintext blob
       DATA_BLOB dataIn;
       dataIn.cbData = plaintext.Length;
       dataIn.pbData = Addr(plaintext[0]);
    
       DATA_BLOB dataOut;
    
       //dataOut = EncryptedFormOf(dataIn)
       BOOL bRes = CryptProtectData(
             dataIn,
             null,     //data description (optional PWideChar)
             null,     //optional entropy (PDATA_BLOB)
             null,     //reserved
             null,     //prompt struct
             CRYPTPROTECT_UI_FORBIDDEN || CRYPTPROTECT_LOCAL_MACHINE,
             ref dataOut);
       if (!bRes) then
       {
          DWORD le = GetLastError();
          throw new Win32Error(le, "Error calling CryptProtectData");
       }
    
       //Copy ciphertext from dataOut blob into an actual array
       bytes[] result;
       SetLength(result, dataOut.cbData);
       CopyMemory(dataOut.pbData, Addr(result[0]), dataOut.cbData);
    
       //When you have finished using the DATA_BLOB structure, free its pbData member by calling the LocalFree function
       LocalFree(HANDLE(dataOut.pbData)); //LocalFree takes a handle, not a pointer. But that's what the SDK says.
    }
    

    加密保护数据 可以在两种模式中的一种模式下运行:

    • 数据只能由
    • 数据可以由在同一台本地计算机上运行的任何人解密(因为它基本上是用本地安全子系统的密码加密的)

    不好的一面 加密保护数据 解密绑定到:

    • 我的机器

    这意味着加密的数据不能传递给其他任何人。我需要在不同的人之间更方便携带的东西。(例如,其他计算机上的人、不在同一域上的人、不在同一域上的人) (域)

    bcrypt(aka BestCrypt,aka Cng,aka CryptoNG,aka Crypto NextGen,aka Cryptography Next Generation API)提供了 Windows 2000时代 加密保护数据 打电话 ProtectSecret .

    • "SID=S-1-1-0" :Everyone组
    • "SID=S-1-5-32-544" :BUILTIN\Administrators组
    • "SID=S-1-5-32-545" :BUILTIN\Users组

    或者通过私人商店中的证书:

    • "CERTIFICATE=HashId:87b8808ecb233e0736b84b60670065b36ca615f1" :中国=youporn.com

    • 它需要Windows 8或更新版本
    • 或者有证书

    我需要一个能和 密码

    我不想自己滚

    Windows是否有一个现有的高级功能来执行密码加密?Windows支持它的一个主要优点是,它们将返回一个支持版本控制的不透明blob。

    所有内容都打包到一个版本化结构中,其中包含进行解密、身份验证所需的所有内容。他们可以改变算法,旧的加密blob仍然可以工作,而新的blob也可以工作。

    另外,我不想自己滚。我们都知道如何使用你自己的加密。这很容易理解 screw up 加密:

    enter image description here

    哦,下一个版本

    enter image description here

    哦,下一个版本

    enter image description here

    • 有窗户的东西
    • 返回一个不透明的blob

    我不使用libnadium的原因是我使用的语言无法使用libnadium。(也不是问题)

    0 回复  |  直到 6 年前
    推荐文章