开发者

Best way to encrypt and decrypt an XML file that serve as a database?

Would like to know the best way to encrypt and 开发者_StackOverflowdecrypt an XML file that serve as a database ?

Thanks.


There are XML encryption APIs included in the .NET Framework that use symmetric and assymetrics keys.

You can also use the standard .NET AES encryption classes for this from any .NET language but you'd have to manually operate on the element/attribute values in the XML (or encrypt it all as one big string). If you are using it as a database encryption can cause some issues if you can't decrypt all of it in one shot. For example if you need to search multiple elements there is going to be a cost to decrypting each one to check the values.

Encryption is not perfect on its own you have to protect the keys used to encrypt the data. Look into the SecureString class and the DPAPI API for protection of the keys, although there may be better APIs for doing this. If you have bugs in your crypto code you might as well not have any encryption, so try to write as little as possible and make sure you have the code reviewed by an expert.


For most uses AES-128 in CTR mode with no padding (or alternatively CBC mode with PKCS7 padding) will suffice to encrypt your file. CTR mode is better if you want to be able to decrypt parts of the file without having to decrypt the whole thing from the start. You just need to store the value of the counter used for each part.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜