1 2 Previous Next 28 Replies Latest reply on Jul 10, 2017 6:30 PM by User16087

    HexDecode issue

    User16087

      Wondering if anyone else has tested this function and found an issue.

       

      I filed a bug report but I'd love to be proven wrong

       

      HexDecode issue

        • 1. Re: HexDecode issue
          fmpdude

          What you found seems like a great thing I would code as a unit test. That is the inverse of the function on a value should be the value again, itself.

           

          Based on all the bugs that are popping up, assuming you have found a bug too, which it sounds like, it doesn't seem that testing is very rigorous at FMI.

           

          Concerning.

          • 2. Re: HexDecode issue
            siplus

            regardless of anything, G(F(X)) = X must hold every time F() is the inverse of G().

            1 of 1 people found this helpful
            • 3. Re: HexDecode issue
              User16087

              I'm not sure what FileMaker anticipated this function to be used for.

              If you do the same unit test with an hex entirely representing visible characters it works

               

              something like HexEncode( HexDecode( "46696C654D616B6572" ) ) works

               

              but that's limited for the real world

              • 4. Re: HexDecode issue
                TomHays

                I suspect that the issue is that you are passing around FileMaker text which might be sanitized for your protection.

                 

                Try

                 

                HexEncode (HexDecode ( "969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d"; "thefile.bin" ))

                 

                to make it use container objects instead.

                 

                 

                -Tom

                1 of 1 people found this helpful
                • 5. Re: HexDecode issue
                  User16087

                  Thanks Tom

                   

                  I had tested that and you are correct. However, using the extra parameters makes things even worse once you use the HexDecode inside CryptAuthCode:

                   

                  CryptAuthCode( "data" ; "SHA256" ; HexDecode ( "969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d"; "thefile.bin" ))

                   

                  HexDecode passes the string "thefile.bin" as the decoded key

                  • 6. Re: HexDecode issue
                    TomHays

                    That may indicate a bug since the Example 2 in the documentation for CryptAuthCode() has that structure suggesting that it should work.

                     

                    The third argument to CryptAuthCode() is "any expression or field" which does not strongly imply to me that a Container is acceptable there.

                     

                    -Tom

                    1 of 1 people found this helpful
                    • 7. Re: HexDecode issue
                      User16087

                      yep.

                      let's see what comes of the bug report. this conversation will be good supporting material

                      • 8. Re: HexDecode issue
                        TomHays

                        How about using Base64Decode( Base64Encode(container)) to get the key data out?

                         

                        CryptAuthCode( "data" ; "SHA256" ; Base64Decode(Base64Encode(HexDecode ( "969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d"; "thefile.bin" ))))

                         

                         

                        -Tom

                        • 9. Re: HexDecode issue
                          User16087

                          not as far as i can see.

                          as stated in the doc the "key" parameter in in CryptAuthCode can be "any expression or field" but the one we are submitting has (and needs to have) non-printable unicode characters when decoded, no matters the format we decode from.

                          my feeling is that the problem lays there in FileMaker relying on a limited set of text characters when decoding.

                          • 10. Re: HexDecode issue
                            fmpdude

                            Yes... Thank you!

                             

                            A simple unit test, right?

                             

                            (The developers do test this stuff, right? I am starting to wonder...)

                             

                            For example, Sin(ArcSin(30)) Had better be.... 30.

                            • 11. Re: HexDecode issue
                              Menno

                              HexEncode is not for converting decimal into hexadecimal and vice versa HexDecode is not for converting hexadecimal into decimal. The example you've given is suggesting that you think it does.

                               

                              If I take your example in the bug report and reverse the function it works fine:

                              HexDecode ( HexEncode( "969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d" ) )

                              has

                              969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d

                              as a result

                              Using only:

                              HexEncode( "969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d" )

                              results in:

                               

                              39363966626239346665623534326237316564653666383766653464356661323963373839333432623066343037343734363730663063323438396530613064

                              If a function for decoding a hexadecimal number into a decimal number would be used on your string the result should be:

                              68129150614252566310535059869040328111768849475142308474775923861927340411405

                              You can do that with little CF which I got from WinfriedHuslik (whom unfortunately has passed away last year):

                              Let ( [

                                   h = "0123456789ABCDEF" ;

                                   hex = Filter ( Upper ( hex ) ; h ) ;

                                   d = Position ( h ; Left ( hex ; 1 ) ; 1 ; 1 ) - 1 ;

                                   s = Length ( hex ) - 1

                              ] ; 

                                   GetAsNumber ( d * ( 16 ^ s ) + Case ( s > 0 ; CF_hex2dec ( Right ( hex ; s ) ) ) )

                              )

                              2 of 2 people found this helpful
                              • 12. Re: HexDecode issue
                                beverly

                                Thanks Menno ! that and other CF's are out there for DEC->HEX->DEC.

                                for others following this thread, a good study of the Container Functions:

                                FileMaker Pro 16 Help

                                Plus you will start seeing a lot more articles and tips at DevCon for ways these can be used.

                                beverly

                                • 13. Re: HexDecode issue
                                  TomHays

                                  I was previously only reading the documentation with no hands-on experience.

                                  After studying the HexEncode() and HexDecode() directly with FileMaker 16, it appears that when you use text arguments to these functions (instead of containers) work via UTF-8.  They are not an arbitrary binary coder/decoder functions when working with FileMaker Text since Text is not a raw binary type.

                                   

                                   

                                  HexEncode("FileMaker") will first interpret the string "FileMaker" as UTF-8 (no BOM) and return the bytes as hexadecimal.

                                  That string consists entirely of ASCII 7-bit characters so there is only one byte per character resulting in

                                  "46696C654D616B6572" as the output.

                                   

                                  HexEncode("€")  // The Euro character Char(8364)

                                  is represented in UTF-8 (no BOM) by 3 bytes.

                                  The resulting output is "E282AC".

                                   

                                  HexDecode(some hex sequence) will attempt to interpret that hex sequence as proper UTF-8 (no BOM) string.

                                  Instead of returning 3 binary values

                                  HexDecode("E282AC") will return the Euro character "€" since that is how it is expressed in UTF-8.

                                   

                                   

                                  HexDecode(an arbitrary Hex string of a binary sequence)

                                  will not work since that string of bytes will be interpreted as UTF-8 and will likely fail to be valid.

                                   

                                  If you need to work with raw binary, use the Container versions of these functions.

                                  HexDecode("E282AC"; "myfile.bin") will generate a container holding the file containing those 3 bytes.

                                  HexDecode("FFFEAC20"; "myfile.bin") will generate a container holding a file containing those 4 bytes.  That just happens to be the same Euro symbol expressed in UTF-16LE (with BOM).

                                   

                                   

                                  In the case of the Key argument to CryptAuthCode(), I don't think there is a way to pass a raw binary key.  It looks like it wants FileMaker Text.

                                   

                                  -Tom

                                  2 of 2 people found this helpful
                                  • 14. Re: HexDecode issue
                                    beverly

                                    Good assessment and thanks for testing, Tom!

                                    See TextEncode() for variations on encoding.

                                     

                                    beverly

                                    1 2 Previous Next