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

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!

Replies are listed 'Best First'.
Re^7: convert hexadecimal value to encrypted string
by dakkar (Hermit) on Dec 11, 2004 at 16:57 UTC

    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)

      I am sure that the table and field names are correct. The encrypted string is stored as a RAW datatype in the table though. It is not CHAR.

      I am trying to verify that the cipher text stored on the database is the same as what I'd obtain by sending a seprate request (using telnet or nc) to the server.

      Two ways to do this would be

      • Extract the text on the database, send it in a decrypt request to the server and then compare the resulting plaintext with the original string(plain text)
      • Send the plaintext in an encrypt request to the server, extract the ciphertext from the response and compare it with the data stored on the database.

      In order to do the first bullet above, I want to obtain the "text" equivalent of the data stored in the database. A describe on the table shows that column from which I extract data is of type RAW (and not CHAR).

      As for the second bullet, I still need a way to convert the hex string on the database server to encrypted form so I can compare it with the encrypted string I receive from the server.

      Thank you

      Terribly sorry for posting an incorrect value of the Base64 encoded encrypted string. It is

      Y52HnyJMoqG6c8xIhNvTYg==

      Now will that help you in suggesting a conversion from the string in the database (639D879F224CA2A1BA73CC4884DBD362) to the a string that is the decoded value of the above base64 string?

      Many thanks

        This works for me:

        my $cypher1_b64='Y52HnyJMoqG6c8xIhNvTYg=='; my $cypher1=decode_base64($cypher1_b64); my $cypher2_hex='639D879F224CA2A1BA73CC4884DBD362'; my $cypher2=pack 'H*',$cypher2_hex; print "ok 1\n" if $cypher1 eq $cypher2;
        -- 
                dakkar - Mobilis in mobile
        

        Most of my code is tested...

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

Re^7: convert hexadecimal value to encrypted string
by Mr. Muskrat (Canon) on Dec 11, 2004 at 15:10 UTC

    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.

      The question still remains. The hex string in the database should be equal to the encrypted string that I receive from the server when I send an encrypt request.

      # The following to get encrypted value from server my $num = 8235; my $request = Create_Request($num,$algorithm,$key,$mode,$iv,$padding); my $response = Send_TCP($request,$server,$port); my $binary = Parse_String($response); # Now $binary should match whatever is stored in database # Create database connection etc.. my $hex = Get_Value($dbh,$table_name,$col_name); # Now is $binary == $hex? # How do I match $hex and $binary ??
      I hope the above makes it clear. For my test to work, I need that $hex should match $binary.

      Thanks