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

    HexDecode issue


      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

          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.



          • 2. Re: HexDecode issue

            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

              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

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




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


                to make it use container objects instead.




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

                  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

                    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.



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


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

                      • 8. Re: HexDecode issue

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


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




                        • 9. Re: HexDecode issue

                          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

                            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

                              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" ) )



                              as a result

                              Using only:

                              HexEncode( "969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d" )

                              results in:



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


                              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

                                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.


                                • 13. Re: HexDecode issue

                                  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.



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

                                    Good assessment and thanks for testing, Tom!

                                    See TextEncode() for variations on encoding.



                                    1 2 Previous Next