Results 1 to 3 of 3

Thread: Encrypting parts of a Serialized File

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Encrypting parts of a Serialized File

    I have some data, mostly contained in ArrayLists. I currently serialize the data, however; I would like to encrypt it.

    I have created an encryption function using AES. The problem is it has to take a byte[] array and return a byte[] array.

    I can encrypt the serialized file, however; some data needs to remain unencrypted. So what I need to do is encrypt the ArrayLists, serialize the file, then when i need to deserialize the file, I decrypt the ArrayLists.

    What's the best way to go about doing this? I'm a bit stumpted right now.

    I thought about serializing data in a memory stream, returning the byte[] and encrypting it. The problem I run into with this stragegy is, how do I store the byte[] arrays so I can serialize them with the rest of my objects and then bring it back?

    I tried encrypting each System.Object inside of the ArrayLists and then putting the encrypted byte[] in. This works, however; I cannot get it back out in byte[] form. I can't deserialize because it's encrypted and casting doesn't work.

    Recommendations?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Encrypting parts of a Serialized File

    I can't give you a completely clear answer on this, but in general terms I'd think that you would create a class that implements ISerializable and then code the encryption into the serialisation right there in the class. You could create the encrytped byte array and convert that to a string before saving to the file. When you deserialise you would convert the string to a byte array and decrypt.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Encrypting parts of a Serialized File

    How would you originally get it into a byte[] array before the serialization?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width