Results 1 to 3 of 3

Thread: [RESOLVED] encrypt and decrypt a binary file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    India
    Posts
    517

    Resolved [RESOLVED] encrypt and decrypt a binary file

    Hello Everyone,

    I need a simple vb.net program which can encrypt/decrypt a binary file such as a PDF. I need to convert pdf to a encrypted file so that no one else can open it.

    My program should only be able to decrypt it. If its possible to decrypt and store in memory without writing output to disk then even better.

    If you guys know how to do this please let me know.

    Thank you,

    Regards,
    GR

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

    Re: encrypt and decrypt a binary file

    There's loads of information around on how to encrypt and decrypt files in VB.NET, on this site and elsewhere. There's really no need for us to reproduce what's already out there. I suggest that you do a bit of research and then put it to use and post back here if you encounter specific issues along the way.

    Note that encryption and decryption is performed on Byte arrays. Where the input Byte arrays come from and where the output Byte arrays go to is of no relevance to the actual encryption and decryption process, so you should keep that in mind. I'd suggest writing methods that take a Byte array as input and output another Byte array. They can then be used for any data. You can then write other methods that make use of those, e.g. a method that reads a file into a Byte array and then passes that to the encryption method and then writes the output to a file or wherever is appropriate.

    The File.ReadAllBytes method can read a file into a single Byte array. If you want to store binary data in memory then you can use a MemoryStream. Note that that will only exist as long as your app is running though, so persisting the data between sessions would still require writing it to a file.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    India
    Posts
    517

    Re: encrypt and decrypt a binary file

    Quote Originally Posted by jmcilhinney View Post
    There's loads of information around on how to encrypt and decrypt files in VB.NET, on this site and elsewhere. There's really no need for us to reproduce what's already out there. I suggest that you do a bit of research and then put it to use and post back here if you encounter specific issues along the way.

    Note that encryption and decryption is performed on Byte arrays. Where the input Byte arrays come from and where the output Byte arrays go to is of no relevance to the actual encryption and decryption process, so you should keep that in mind. I'd suggest writing methods that take a Byte array as input and output another Byte array. They can then be used for any data. You can then write other methods that make use of those, e.g. a method that reads a file into a Byte array and then passes that to the encryption method and then writes the output to a file or wherever is appropriate.

    The File.ReadAllBytes method can read a file into a single Byte array. If you want to store binary data in memory then you can use a MemoryStream. Note that that will only exist as long as your app is running though, so persisting the data between sessions would still require writing it to a file.
    Thank you for your advice. I did actually search but mostly found simple method that took plain text as input and output. In one of the methods when I passed pdf file binary structure it took forever to encrypt.

    Luckily today I found a link which helped : http://www.obviex.com/samples/Encryption.aspx


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