Python Forum
Converting python to FileMaker
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting python to FileMaker
#1
I need to convert a client's python code for generating a login code to something similar in FileMaker. I didn't think this could be done in FileMaker, but discovered some new functions that I think will work.
The code in python is:
import sys
from hashlib import sha1
import hmac
import base64
def create_signature(secret_key):
    hashed = hmac.new(secret_key, sha1)
    return hashed

    ip = 10.0.53.34

    digest_str = "wordswords" + ip + "andmorewords"
    hash = hmac.new("lg2acC8jnKcIFzGXVcLH3XlBmPNW4ypOnIE2OlSTFBw2sENEel7YuWP5Sojxjjp",
                       digest_str,
                       sha1)
    b64_hash = base64.b64encode(hash.digest()).decode()

I'm completely confused by the last line.
This generates the same code every time based on the ip in python. Everything that I've tried in FileMaker, using CryptAuthCode, CryptDigest and CryptEncryptBase64 or CryptDecryptBase64 creates a different code each time.

Thanks for any help you can provide.
Damian
Yoriz write Sep-18-2022, 04:52 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
(Sep-18-2022, 04:45 PM)DWolf Wrote: I'm completely confused by the last line.
The last lines encodes the (probably binary) hash digest in base 64 but the result is a Python bytes type, so the final .decode() converts it to a sequence of unicode characters.
Reply
#3
(Sep-18-2022, 07:51 PM)Gribouillis Wrote:
(Sep-18-2022, 04:45 PM)DWolf Wrote: I'm completely confused by the last line.
The last lines encodes the (probably binary) hash digest in base 64 but the result is a Python bytes type, so the final .decode() converts it to a sequence of unicode characters.

So there are only 2 operations that are done, creating the hash and then converting it to unicode?
Reply
#4
There is an indention problem in the above code. I think lines 9 to 15 should not be indented as there is a return statement in function create_signature() at line 7. This function is not used, otherwise yes, the code creates a hmac object and computes the base 64 version of the hmac's digest and does nothing else.
Reply
#5
Thanks for you help Gribouillis!
There are a number of different Crypt functions in FileMaker. I've converted the python into what I believe are the equivalents.

CryptAuthCode( $Key; "SHA1"; $Digest )
this returns a binary HMAC using the specified hash algorithm

$Decode = CryptEncryptBase64( $HMAC; $Key )
encrypts $HMAC with the specified key and returns text in Base64 format.

Base64Decode ( $Decode )

This generates characters that look similar to what the python code does, but they change with each run and aren't the same.
Reply
#6
(Sep-20-2022, 11:36 AM)DWolf Wrote: This generates characters that look similar to what the python code does, but they change with each run and aren't the same.
I can't help you debug this because I don't know Filemaker's functions an language. Also an understanding of RFC 2104 may be necessary for this. Is there a Filemaker's forum somewhere?
Reply
#7
(Sep-20-2022, 12:08 PM)Gribouillis Wrote:
(Sep-20-2022, 11:36 AM)DWolf Wrote: This generates characters that look similar to what the python code does, but they change with each run and aren't the same.
I can't help you debug this because I don't know Filemaker's functions an language. Also an understanding of RFC 2104 may be necessary for this. Is there a Filemaker's forum somewhere?

For sure, the worst is translating one from another. I know FileMaker pretty well and want to convert more to python. None of this crypto stuff had been necessary until recently. And despite being generally versed on all it, the specific implementations can build brain cells, or demonstrate the total loss of all of them.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting python to c# benahmadi 1 2,656 Oct-22-2019, 09:50 PM
Last Post: micseydel
  converting array to and from string in python 3.7.2 srm 5 6,219 Jul-03-2019, 01:11 PM
Last Post: snippsat
  help with converting C# function to Python korenron 17 11,353 May-19-2019, 10:26 AM
Last Post: Gribouillis
  Converting R code to python mcva 2 12,538 Mar-09-2019, 04:01 PM
Last Post: mcva
  converting from c# to python peper 1 2,961 Jun-12-2018, 05:19 PM
Last Post: micseydel
  converting python script to another version gptura 5 4,750 Mar-13-2018, 12:16 PM
Last Post: gptura
  Converting Pseudocode to Python ncp511 1 5,147 Jan-16-2018, 04:34 PM
Last Post: Windspar
  Resources for converting Python 2.x code to 3.x Luke_Drillbrain 4 5,034 May-03-2017, 06:34 PM
Last Post: snippsat
  Need help converting some code from python 2.7 to 3.5 Blue Dog 3 4,903 Oct-18-2016, 12:30 AM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020