Determin if a binary file is encrypted

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TheLostLeaf

    Determin if a binary file is encrypted

    Hi,

    I wote some code that encrypts binary files, and decrypts them, works
    great. It uses the same file name, so if the file is called
    mountain.jpg, it encrypts it with the same name.

    I'm using Rijndael, is there a script I can write that can tell if the
    file is encrypted before i try to read it into a picturebox or
    something.

    One way i can tell is it error on load as not a valid image, but i
    want to be able to do it with all files.

    Thanks !



  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: Determin if a binary file is encrypted

    TheLostLeaf wrote:
    I wote some code that encrypts binary files, and decrypts them, works
    great. It uses the same file name, so if the file is called
    mountain.jpg, it encrypts it with the same name.
    >
    I'm using Rijndael, is there a script I can write that can tell if the
    file is encrypted before i try to read it into a picturebox or
    something.
    >
    One way i can tell is it error on load as not a valid image, but i
    want to be able to do it with all files.
    In general: no. There is nothing preventing that the same file
    can be both an encrypted file and an image. So you can not
    distinguish.

    If you are willing to limit yourself to a small set of
    graphics formats, then you can check if the file matches
    a header for that file type (magic value and other known
    values).

    Arne

    Comment

    • TheLostLeaf

      #3
      Re: Determin if a binary file is encrypted

      On Aug 1, 12:11 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
      TheLostLeaf wrote:
      I wote some code that encrypts binary files, and decrypts them, works
      great. It uses the same file name, so if the file is called
      mountain.jpg, it encrypts it with the same name.
      >
      I'm using Rijndael, is there a script I can write that can tell if the
      file is encrypted before i try to read it into a picturebox or
      something.
      >
      One way i can tell is it error on load as not a valid image, but i
      want to be able to do it with all files.
      >
      In general: no. There is nothing preventing that the same file
      can be both an encrypted file and an image. So you can not
      distinguish.
      >
      If you are willing to limit yourself to a small set of
      graphics formats, then you can check if the file matches
      a header for that file type (magic value and other known
      values).
      >
      Arne
      Thanks, I think i will rename the file with an extra extention, like
      mountain.jpg.en c. I didn't know if I could same the BOF or EOF for a
      tell take char that might occur with any Rijndael encrypt.

      Comment

      • Peter Duniho

        #4
        Re: Determin if a binary file is encrypted

        On Fri, 01 Aug 2008 12:00:29 -0700, TheLostLeaf <eric@canyondig ital.com>
        wrote:
        I wote some code that encrypts binary files, and decrypts them, works
        great. It uses the same file name, so if the file is called
        mountain.jpg, it encrypts it with the same name.
        >
        I'm using Rijndael, is there a script I can write that can tell if the
        file is encrypted before i try to read it into a picturebox or
        something.
        >
        One way i can tell is it error on load as not a valid image, but i
        want to be able to do it with all files.
        You can follow a filename convention, but of course that will only work as
        long as no one changes the file name.

        My general approach when encoding data is to attempt to decode the data in
        the deepest encoding first, and work my way back. So in your case, rather
        than trying to load the data as an image, you should be trying to decrypt
        it. If the decryption fails, then you know it's _not_ encrypted and so
        can move on to the next likely stage (e.g. loading it as an image).

        If you knew the data was only one of two formats, you could do either
        attempt first. But you might as well rule out the encryption first, since
        that will tell you for any file whether it's been encrypted or not.

        Pete

        Comment

        Working...