<p>I'd like to be able to pass a SecureString (a cached passphrase) to a child process in C# (.Net 3.5), but I don't know what the most secure way is to do it. If I were to convert the SecureString back to a regular string and pass it as a command-line argument, for example, then I <em>think</em> the value may be prone to disk paging--which would make the plaintext touch the filesystem and ruin the point of using SecureString.</p>

<p>Can the IntPtr for the SecureString be passed instead? Could I use a named pipe without increasing the risk?</p>

[{'answer_id': 46746, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 0, 'selected': False, 'text': "<p>Unless your child process also understands how to work with SecureString I don't think there is a way to pass it directly. For example, the Process.Start() method has two overloads that take a SecureString so the risk of the actual string value being sniffed is minimized (it's still possible since somewhere along the the way the actual value has to be retrieved/unmarshalled).</p>\n\n<p>I think a lot of how to do this will depend on what the child process is and how it is being started.</p>\n"}, {'answer_id': 47320, 'author': 'Grey Panther', 'author_id': 1265, 'author_profile': 'https://Stackoverflow.com/users/1265', 'pm_score': 3, 'selected': True, 'text': "<p>In general you should define your threat model before worrying about more exotic attacks. In this case: are you worried that somebody shuts down the computer and does a forensic analysis of the harddrive? Application memory can also be swapped out, so the simple fact that <em>one</em> process has it in memory, makes it potentially possible for it to end in the swap file. What about hibernation? During hibernation the entire content of the memory is written to the harddisk (including the SecureString - and presumably the encryption key!). What if the attacker has access to the system <em>while it's running</em> and can search through the memory of applications?</p>\n\n<p>In general client side security is very tricky and unless you have dedicated hardware (like a TPM chip) it is almost impossible to get right. Two solutions would be:</p>\n\n<ul>\n<li>If you only need to test for equality between two strings (ie: is this string the same as the one I had earlier), store only a (salted) hash value of it.</li>\n<li>Make the user re-enter the information when it is needed a second time (not very convenient, but security and convenience are opposed to each other)</li>\n</ul>\n"}]
['https://Stackoverflow.com/questions/46693', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5548/']