authenticvision / libpaseto

C implementation of Platform-Agnostic Security Tokens (PASETO)
https://paseto.io
BSD 3-Clause "New" or "Revised" License
22 stars 2 forks source link

Unable to load V2 secret or public key with base64 #9

Closed peterwallhead closed 1 year ago

peterwallhead commented 1 year ago

Using an ESP32. Coding in Arduino.

I'm attempting to use paseto_v2_public_load_secret_key_base64 and paseto_v2_public_load_public_key_base64 functions but I'm unable to load the the keys.

I've attempted many different base64 encoding methods, including the base encoded strings generated by openssl, but not had any luck so far.

I note that https://github.com/authenticvision/libpaseto/blob/master/examples/example.c is the paseto_v2_local_load_key_base64 function and this works as expected.

I also note that you've written some tests for the paseto_v2_public_load_secret_key_hex function, and using this function with the same hex encoded strings works as expected.

Would you be able to add an example using the paseto_v2_public_load_secret_key_base64 and paseto_v2_public_load_public_key_base64 functions please?

minus7 commented 1 year ago

I've added an example to generate keys and one using the v2.public API. The *_base64 functions expect base64-encoded text using the URL variant (i.e. - and _ instead of + and /) and omit the = padding. I hope this helps.

peterwallhead commented 1 year ago

Brilliant, thank you for your quick reply and work!

Looks like base64-encoding the keys using the URL variant was the missing step here.

I'll replicate your examples into my code next week and update you.

If I get time I'll have a go at adding in some more test cases for the V2.public API for you too.

peterwallhead commented 1 year ago

I was able to integrate your example code into my project quickly and seamlessly. Thank you again.