假設您的C++編譯器以公共語言運行時(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
http://stackoverflow.com/questions/1508082/how-is-a-securestring-marshalled-to-unmanaged-code – Ralf
你只打算能夠派遣,作爲純文本,也許看在使用C#中的ProtectedData.Protect和C++中的CryptUnprotectData時,都使用DPAPI –
@Ralf我特別說我試圖避免編組。 – njbuwm