1

How do i Append multiple SecureStrings?

because i cant do

SecureString pepper 
SecureString salt
SecureString pepperAndSalt = pepper + salt;

and if i would use
SecureString.AppendChar(Char)
i would have to convert salt into a insecure char array which is something i would like to avoid.

leppie
  • 115,091
  • 17
  • 196
  • 297
WiiMaxx
  • 5,322
  • 8
  • 51
  • 89

2 Answers2

2

You can't1, by definition:

Note that SecureString has no members that inspect, compare, or convert the value of a SecureString. The absence of such members helps protect the value of the instance from accidental or malicious exposure. Use appropriate members of the System.Runtime.InteropServices.Marshal class, such as the SecureStringToBSTR method, to manipulate the value of a SecureString object.

Once you get a value in, you can't take it out.

1: Unless you're willing to start using unmanaged code by using Marshal.SecureStringToBSTR, but that would defy the usage of SecureString

Albireo
  • 10,977
  • 13
  • 62
  • 96
  • so it seems like i have to accept that there will no way to do this secure – WiiMaxx Nov 27 '15 at 10:38
  • 1
    Not unless you decide to sift through unmanaged memory with `SecureStringToBSTR` (and remember to clean up after yourself). But is it worth to use `SecureString` in your scenario? Is it really providing added security? (By the way, a cryptographic salt [is meant to be public](http://crypto.stackexchange.com/q/1776).) – Albireo Nov 27 '15 at 10:45
  • you are right, sometimes i do muse to much and lose focus of the whole thing – WiiMaxx Nov 27 '15 at 11:01
0

A work around can be using the System.Runtime.InteropServices.Marshal class as described in this answer to convert the secure string to string, append both the strings and convert the concatenated string back to secure string

Community
  • 1
  • 1
Kayani
  • 942
  • 7
  • 23
  • this would defeat the use of a `SecureString` – WiiMaxx Nov 27 '15 at 10:34
  • true but if there is no other way than there will be a trade off between security and getting the job done – Kayani Nov 27 '15 at 10:41
  • 1
    Converting a `SecureString` back to a `String` completely defeats the purpose of using a `SecureString` in the first place. The only reasonable way to manipulate them is by handling the memory directly (second snippet in the answer to the question you linked). – Albireo Nov 27 '15 at 10:49