in reply to Re^3: convert hexadecimal value to encrypted string
in thread convert hexadecimal value to encrypted string

That is what I am trying to do. In order to send the data back to the encryption server, I need to read it from the database first, create a request and then send it to the server.

The problem I am seeing right now is that the data I have extracted from the database is in Hex format like the string I posted earlier (639D879F224CA2A1BA73CC4884DBD362) and the server does not recognize this as a valid cipher text (sending a request with this string results in error). That is the reason I wish to convert the hex string to a "string format" using pack/unpack so that I can send the "correct" ciphertext to the server. IMHO, a conversion of the hex number to a regular string should work.

Thanks!

  • Comment on Re^4: convert hexadecimal value to encrypted string

Replies are listed 'Best First'.
Re^5: convert hexadecimal value to encrypted string
by diotalevi (Canon) on Dec 11, 2004 at 03:11 UTC
    Aha. I see. When I tried to pack your string I noticed that perl thought that it was being given unicode data and treated it accordingly. Instead of plain pack "H*", $str, try do { use bytes; pack "H*", $str }. See bytes for more on forcing perl to not try to interpret it as unicode.

    Oh further drat. when I wrote that I saw things like \323 and thought "aha! a value over 255, obviously unicode." Unfortunately for me, that was an octal number and this whole digression on unicode is entirely unrelated. So, show us the value produced by the encryption server and the value fetched from the database. As-is, there isn't anything that you're doing wrong.

      Here's how the database stores the encrypted string:

      639D879F224CA2A1BA73CC4884DBD362

      I know the plaintext string that corresponds to the above cipher text. It is

      8235

      I can send an encrypt request to the server with the above string, and obtain the encrypted data. Since it contains unprintable characters, I am giving you the Base64 encoded the value of the encrypted string. You can obtain the encrypted string by simply running

      perl -MMIME::Base64 -e 'print decode_base64($str) . "\n";'
      to get the encrypted string.

      The Base 64 encoded string of the encrypted string is

      vY+TqCu5/Wdg6O+ilDqHVQ==

      As mentioned earlier I want to verify that the encryption/decryption process works ok. So the hex string at the beginning of this post should be equal to the Base64 decoded string vY+TqCu5/Wdg6O+ilDqHVQ==

      Thanks a lot for your time!

        Let me get this straight...

        You have a byte string, your plaintext, it being (as hex bytes) 38-32-33-35, or (as ASCII chars) '8235'.

        You send it to your encryption server, and you get back a byte string, your cyphertext, it being (as base64) 'vY+TqCu5/Wdg6O+ilDqHVQ==', or (as hex bytes) bd-8f-93-a8-2b-b9-fd-67-60-e8-ef-a2-94-3a-87-55.

        Then you have something in a field in a database, that should be the same cyphertext, stored as hex digits in a CHAR column. The value you have is (as hex digits) 63-9D-87-9F-22-4C-A2-A1-BA-73-CC-48-84-DB-D3-62.

        It is not the same value as the one corresponding to the base64-encoded string you posted. Are you sure you are reading from the correct row in the table? Otherwise I missed some steps in your process.

        -- 
                dakkar - Mobilis in mobile
        

        Most of my code is tested...

        Perl is strongly typed, it just has very few types (Dan)

        Thanks for finally clarifying what you are trying to do with the hex string. Now have you answered you own question? Or do questions still remain? It's unclear from this post.