C#'无法从'char []'转换为'char *'

时间:2017-06-27 05:49:17

标签: c#

我在使用C#

的流程中添加密码凭据时遇到问题

目前看起来如下:

char[] passwordChars = {'x', 'x', 'x', '@', 'x', 'x', 'x', 'x'} ;
System.Security.SecureString ssPwd = new SecureString(passwordChars, passwordChars.Length);

我想知道如何继续将它从char []转换为char *。

2 个答案:

答案 0 :(得分:1)

SecureString documentation开始:

System.Security.SecureString ssPwd;
char[] passwordChars = {'x', 'x', 'x', '@', 'x', 'x', 'x', 'x'} ;
fixed(char* pChars = passwordChars)
{
   ssPwd = new SecureString(pChars, chars.Length);
}


//Don't forget to dispose of your string after you're done with it:
ssPwd.Dispose();

答案 1 :(得分:1)

char[] passwordChars = { 'x', 'x', 'x', '@', 'x', 'x', 'x', 'x' };
System.Security.SecureString ssPwd = new SecureString();
foreach (var c in passwordChars)
{
    ssPwd.AppendChar(c);
}
ssPwd.MakeReadOnly();