gpt4 book ai didi

c# - C++ 中是否有等效的 C# SecureString?

转载 作者:行者123 更新时间:2023-11-30 05:34:50 24 4
gpt4 key购买 nike

我的 C# 代码中有一个 SecureString,我需要将其传递到 DLL 中。我宁愿不进行编码,因为当这种情况发生时,SecureString 似乎是未加密的(因此不再安全)。所以问题是在 C++ 中是否有等效的 C# SecureString 以便我可以将 SecureString 从我的 C# 代码传递到 C++ DLL ... 或者是否有更好/不同的方式,这样我就不需要解密SecureString 以将其传递给 DLL。

最佳答案

假设您的 C++ 编译器以公共(public)语言运行时 (CLR) 为目标,您可以使用相同的 SecureString 实现。

using namespace System;
using namespace System::Security;

int main(array<System::String ^> ^args)
{
// Define the string value to assign to a new secure string.
Char chars[4] = { 't', 'e', 's', 't' };
// Instantiate the secure string.
SecureString^ testString = gcnew SecureString();
// Assign the character array to the secure string.
for each (Char ch in chars)
{
testString->AppendChar(ch);
}
// Display secure string length.
Console::WriteLine("The length of the string is {0} characters.",
testString->Length);

delete testString;
return 0;
}
// The example displays the following output:
// The length of the string is 4 characters 4 characters

关于c# - C++ 中是否有等效的 C# SecureString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34067372/

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