I am stuck trying to verify a token that does verify just fine on jwt.io. Kindy look at this code and let me know what I did understand wrong.
token=“eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiIsInR5cCI6InBhc3Nwb3J0IiwieDV1IjoiaHR0cHM6Ly9hei50YXgvMSJ9.eyJhdHRlc3QiOiJBIiwiZGVzdCI6eyJ0biI6WyIxOTU0NDQ0NzQwOCJdfSwiaWF0IjoxNjc2MjY1NTE0LCJvcmlnIjp7InRuIjoiMTcyNzQ0MzMwMTkifSwib3JpZ2lkIjoiMzU4ZDA0OGItZTAwNy0xMWVhLWFjMzctNDctMjA1LTE3Mi04OSJ9.YD9kpeGaKFa6Gh-TIX7mAJWl9W3EpitTCpHxS7UEmddfT0E3DfRvpwE
IsGqC8ouKxwmuYGKq1hvgucKqLLYFhA”
echo “${token}” > token.txt
echo “-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEkCmapE3ygZFy5ZDAjFSGh5rp766W
EZ2+adZvlPeVk5kJzenhDJROfhh7aIKiG/npK8VnYE0WOf2OjyJU6LE9OQ==
-----END PUBLIC KEY-----” > pk.pem
IFS=‘.’ read -r header payload signature <<< “$token”
echo “$signature” > signature.bin
echo “${token}”|openssl dgst -sha256 -binary > payload_hash.bin
openssl pkeyutl -verify -inkey pk.pem -pubin -sigfile signature.bin -in payload_hash.bin
echo “${header}.${payload}.${signature}” > token1.txt