C ++中是否有等效的C#SecureString? [英] Is there a C# SecureString equivalent in C++?

查看:111
本文介绍了C ++中是否有等效的C#SecureString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a SecureString in my C# code that I need to pass into a DLL. I would prefer to not do a Marshalling as it seems that when this occurs the SecureString is unencrypted (and hence not secure anymore). So the question is whether or not there is a C# SecureString equivalent in C++ so that I can pass the SecureString from my C# code into the C++ DLL ... or if there is a better/different way such that I do not need to unencrypt the SecureString to pass it to the DLL.

推荐答案

假设您的C ++编译器针对公共语言运行时(CLR),则可以使用相同的SecureString实现.

Assuming your C++ compiler target the Common Language Runtime (CLR), you can use the same SecureString implementation.

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#SecureString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆