如何使用 Microsoft CryptoAPI(CryptDeriveKey、BCrypt[...] 函数、CryptAcquireContext 等)将以下加密代码(VB.NET 4.0)转换为等效的 C++ 代码?(我在 Internet 上没有找到一篇描述使用 Microsoft CryptoAPI 的 AES 的文章……)
Dim Key(31) As Byte
Dim IV(15) As Byte
Array.Copy(SomeByteArray, IV, 16)
Array.Copy((New SHA512Managed).ComputeHash(SomeByteArray), Key, 32)
Using AESEncr As New RijndaelManaged() With {.Padding = PaddingMode.ISO10126}
FinalEncrypted = AESEncr.CreateEncryptor(Key, IV).TransformFinalBlock(AnotherByteArray, 0, AnotherByteArray.GetLength(0))
End Using
和解密一个:
Dim Key(31) As Byte
Dim IV(15) As Byte
Array.Copy(SomeByteArray, IV, 16)
Array.Copy((New SHA512Managed).ComputeHash(SomeByteArray), Key, 32)
Using AESEncr As New RijndaelManaged() With {.Padding = PaddingMode.ISO10126}
FinalDecrypted = AESEncr.CreateDecryptor(Key, IV).TransformFinalBlock(FinalEncrypted, 0, FinalEncrypted.GetLength(0))
End Using
(注意:我已经有关于 SHA-512 方法的 C++ 代码,所以不要为此烦恼。)