[Python] Sets a value for the encryption and decryption key Tink-FPE [closed]

Discussão em 'Python' iniciado por Stack, Setembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    I would like to use the tink-fpe library to use format-preserving encryption for a database.

    Using the preservation of the key in JSON format, I can't figure out how to define my own key for encryption and decryption.

    Here is the test code:

    import json
    from tink import JsonKeysetReader
    from tink import cleartext_keyset_handle
    import tink_fpe

    tink_fpe.register()

    keyset_json = json.dumps({
    "primaryKeyId": 1382079328,
    "key": [
    {
    "keyData": {
    "typeUrl": "type.googleapis.com/ssb.crypto.tink.FpeFfxKey",
    "value": "EhD4978shQNRpBNaBjbF4KO4GkIQAho+QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODk=",
    "keyMaterialType": "SYMMETRIC"
    },
    "status": "ENABLED",
    "keyId": 1382079328,
    "outputPrefixType": "RAW"
    }
    ]
    })

    keyset_handle = cleartext_keyset_handle.read(JsonKeysetReader(keyset_json))
    fpe = keyset_handle.primitive(tink_fpe.Fpe)


    During my research, I found that I need to change the value defined in the json: "value". From what I know, value is in base64 and when I decrypt, I find as value: ø÷¿,...Q¤Z6Åà£B>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

    I know that I have to change the value of: ø÷¿,...Q¤Z6Åà£B> to my own value, but I don't know how to do it exactly.

    Continue reading...

Compartilhe esta Página