How to use SecureStringToBSTR in .net standard? (convert SecureString to IntPtr)

天涯浪子 提交于 2019-12-11 06:19:56

问题


I would like to convert a SecureString to an IntPtr. Until now, in .net 4.7 I was using this way:

try
{
    IntPtr bstr1 = IntPtr.Zero;
    bstr1 = Marshal.SecureStringToBSTR(ss1);
}
finally
{
    if (bstr2 != IntPtr.Zero) Marshal.ZeroFreeBSTR(bstr2);
    if (bstr1 != IntPtr.Zero) Marshal.ZeroFreeBSTR(bstr1);
}

But I am trying to convert this project to .net standard 1.6, but the method is not available in Marshal type.

So I would like to know how to convert the SecureString to IntPtr in .net standard.

Thanks.

来源:https://stackoverflow.com/questions/44542611/how-to-use-securestringtobstr-in-net-standard-convert-securestring-to-intptr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!