2017-06-27 3 views
0

私はC#のC#* 『文字『から』文字[]「から変換することはできません』

を使用して、プロセスにパスワードの資格情報を追加することで問題を抱えています現在、それは以下のようになります。

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

I私はchar [*]からchar *に変換する方法についてどう思っていますか?

+5

*「このAPIは、製品のインフラストラクチャをサポートします。コードから直接使用するためのものではありません。」*おそらく、代わりに繰り返し 'AppendChar'を使用してください。 (配列内の 'passwordChars'が既に' SecureString'のポイントを部分的に破っているという事実) – Ryan

+1

'SecureString'はもはや安全であるとはみなされません。 [here](https://stackoverflow.com/questions/44254774/how-to-remove-string-from-process-memory/44255219#comment75519234_44255219) – Rob

答えて

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(); 
+0

を参照してください。 「引数1はありません'ref'キーワード " – Hex02

+0

"と一致するようにしてください。 '安全でない{}'文脈でそれをラップする必要があるかもしれません。 – FrankerZ

+2

Hm、セキュアな文字列を作るための安全でないコード。それはほとんど詩的なように聞こえる。 –

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(); 
+0

このコードを使用することができます。 –

関連する問題