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
- Convert the
SecureString
to aBSTR
viaSecureStringToBSTR
- Encrypt the
BSTR
- 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.
精彩评论