开发者

How do I store a SecureString in the registry?

开发者 https://www.devze.com 2023-03-09 21:05 出处:网络
I want to开发者_开发技巧 store a System.SecureString in the registry. Is that possible? And how would I go about doing it?

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消