Andrew J. Brehm
Andrew J. Brehm

Reputation: 4768

How do I store a SecureString in the registry?

I want to store a System.SecureString in the registry. Is that possible? And how would I go about doing it?

Would my program be able to decrypt the string again when running the next time?

Upvotes: 1

Views: 1396

Answers (2)

nithins
nithins

Reputation: 3192

Take a look at the Storing Private Data article in MSDN. You'll have to pInvoke the LsaStorePrivateData() call.

Upvotes: 1

JaredPar
JaredPar

Reputation: 755041

It's not possible to do in encrypted form without a helper layer. It' doesn't natively support any form of serialization and in fact cannot even be inspected in it's native form. To even get any information out of it you need to go through PInvoke or the SecureStringToBSTR API. Both of which will give you access to the string in unencrypted form.

One way I could see this working is

  1. Convert the SecureString to a BSTR via SecureStringToBSTR
  2. Encrypt the BSTR
  3. Store the result in the registry

Of course you'd need to use an encryption mechanism which was re-usable between instances of your program.

Upvotes: 3

Related Questions