Binary Encryption

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

    Binary Encryption

    Im using md5 to encrypt and decrypt plain text, this works fine...

    When i try to run the same function on a binary file, it does not
    decrypt correctly. Is there a way to encrypt binary files correctly,
    and be able to decrypt them?

    in the perfect situation i would like to be able to store the
    encrypted binary file into a mysql blob field, or at least be able to
    save an encrypted version of the binary file on the server.

    Im not lookign for a copy paste soultion (although i would take one) -
    but maybe some reliable documention or examples?

    Thanks,
    Phil
  • Michael Fesser

    #2
    Re: Binary Encryption

    .oO(Phil Palmieri)
    [color=blue]
    >Im using md5 to encrypt and decrypt plain text, this works fine...[/color]

    Huh?
    [color=blue]
    >When i try to run the same function on a binary file, it does not
    >decrypt correctly. Is there a way to encrypt binary files correctly,
    >and be able to decrypt them?[/color]

    MD5 is a hash algorithm, which is not reversible by definition. In other
    words: You can't decrypt a hash.
    [color=blue]
    >in the perfect situation i would like to be able to store the
    >encrypted binary file into a mysql blob field, or at least be able to
    >save an encrypted version of the binary file on the server.[/color]

    In most cases it's better to store binary data in real files. Storing it
    as BLOBs in a database will probably slow down the db server and make
    queries inefficient.

    Anyway, you might want to have a look at Mcrypt.



    PHP's Encryption Functionality [page 3]
    Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology


    Micha

    Comment

    • Phil Palmieri

      #3
      Re: Binary Encryption

      Ok, maybe i didnt explain that well...

      Irregardless of what im using, im encrypting a string so.. "Phil" +
      "password(s )" becomes "#sakdhk3hk34s2 "; (not real i just typed
      gibbrish); and then can be reversed.

      forget the database for now, -- If i run my encryption function on
      the contents of a ASCII file (using fopen) i can encrypt and decrypt
      it fine, so i tried with my fingers crossed to see if it would work on
      a binary file -- it didn't.

      So, Pretending im starting from scratch, how would i encrypt a binary
      file? and then be able to decrypt it using a 'password'.

      So FILE + "password" = 'garbage'
      and garbage + "password" = FILE
      --

      If i cant nativly do it in PHP, is there Server based software i can
      install and just run cron system commands?

      Thanks,
      PHil


      Michael Fesser <netizen@gmx.ne t> wrote in message news:<1j0jo0d37 gn1td8imncna2hk m5v5va8r6j@4ax. com>...[color=blue]
      > .oO(Phil Palmieri)
      >[color=green]
      > >Im using md5 to encrypt and decrypt plain text, this works fine...[/color]
      >
      > Huh?
      >[color=green]
      > >When i try to run the same function on a binary file, it does not
      > >decrypt correctly. Is there a way to encrypt binary files correctly,
      > >and be able to decrypt them?[/color]
      >
      > MD5 is a hash algorithm, which is not reversible by definition. In other
      > words: You can't decrypt a hash.
      >[color=green]
      > >in the perfect situation i would like to be able to store the
      > >encrypted binary file into a mysql blob field, or at least be able to
      > >save an encrypted version of the binary file on the server.[/color]
      >
      > In most cases it's better to store binary data in real files. Storing it
      > as BLOBs in a database will probably slow down the db server and make
      > queries inefficient.
      >
      > Anyway, you might want to have a look at Mcrypt.
      >
      > http://www.php.net/mcrypt
      >
      > PHP's Encryption Functionality [page 3]
      > http://www.onlamp.com/pub/a/php/2001...pt.html?page=3
      >
      > Micha[/color]

      Comment

      • neur0maniak

        #4
        Re: Binary Encryption

        How can it be irregardless of encryption method?
        You're probably not using a binary-safe encryption method.

        If that's the case, Base64 encode your binary file, then encrypt that.
        When decrypting, just remember to base64 decode the output.

        Phil Palmieri wrote:[color=blue]
        > Ok, maybe i didnt explain that well...
        >
        > Irregardless of what im using, im encrypting a string so.. "Phil" +
        > "password(s )" becomes "#sakdhk3hk34s2 "; (not real i just typed
        > gibbrish); and then can be reversed.
        >
        > forget the database for now, -- If i run my encryption function on
        > the contents of a ASCII file (using fopen) i can encrypt and decrypt
        > it fine, so i tried with my fingers crossed to see if it would work on
        > a binary file -- it didn't.
        >
        > So, Pretending im starting from scratch, how would i encrypt a binary
        > file? and then be able to decrypt it using a 'password'.
        >
        > So FILE + "password" = 'garbage'
        > and garbage + "password" = FILE
        > --
        >
        > If i cant nativly do it in PHP, is there Server based software i can
        > install and just run cron system commands?
        >
        > Thanks,
        > PHil
        >
        >
        > Michael Fesser <netizen@gmx.ne t> wrote in message news:<1j0jo0d37 gn1td8imncna2hk m5v5va8r6j@4ax. com>...
        >[color=green]
        >>.oO(Phil Palmieri)
        >>
        >>[color=darkred]
        >>>Im using md5 to encrypt and decrypt plain text, this works fine...[/color]
        >>
        >>Huh?
        >>
        >>[color=darkred]
        >>>When i try to run the same function on a binary file, it does not
        >>>decrypt correctly. Is there a way to encrypt binary files correctly,
        >>>and be able to decrypt them?[/color]
        >>
        >>MD5 is a hash algorithm, which is not reversible by definition. In other
        >>words: You can't decrypt a hash.
        >>
        >>[color=darkred]
        >>>in the perfect situation i would like to be able to store the
        >>>encrypted binary file into a mysql blob field, or at least be able to
        >>>save an encrypted version of the binary file on the server.[/color]
        >>
        >>In most cases it's better to store binary data in real files. Storing it
        >>as BLOBs in a database will probably slow down the db server and make
        >>queries inefficient.
        >>
        >>Anyway, you might want to have a look at Mcrypt.
        >>
        >>http://www.php.net/mcrypt
        >>
        >>PHP's Encryption Functionality [page 3]
        >>http://www.onlamp.com/pub/a/php/2001...pt.html?page=3
        >>
        >>Micha[/color][/color]

        Comment

        Working...