简体   繁体   中英

How can I store a string of encrypted data in an xml element?

So I have EntityFramework solution. i have customized the context to insert an audit trail, and it stores the trail in an xml field. the context serializes an entity and that is what is stored. I have certain fields that i am encrypting before they are written to the db. I have a helper class that uses AESManaged to perform the encryption. The values that wind up being stored contain ascii special characters, and this causes an exception during serialization.

my question is, how should i hande these encrypted fields so that they can be serialized?

You can use Convert.ToBase64String . Just don't store anyway to decrypt it.

byte[] encryptedBytes = ...;
var asBase64 = Convert.ToBase64String(encryptedBytes);
var asBytes = Convert.FromBase64String(asBase64);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM