Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last byte missing? #1

Open
lucashenning opened this issue Mar 29, 2023 · 0 comments
Open

Last byte missing? #1

lucashenning opened this issue Mar 29, 2023 · 0 comments

Comments

@lucashenning
Copy link

lucashenning commented Mar 29, 2023

Hi @hir0min,

first off, thank you for putting this together. Must have been a lot of work!

I ran into a small problem when I was trying to decode the following base64url encoded value:

bytes n = hex'736775494b49766c4556427345476b3737695632794e517870595f516b69793379754d66593477706d6e506c65766c444b4153753675505f434775627a54686942486c43685944444e7659664f6974575844777078624a5f4d716d616a412d6444627249354c646767794a70536f57504b5468504a31434b5268526952584a6a5847693647673654666259527775307a697944675a5a3132354e737a754e4f554f317063317147756e34535069667a59374f5936427441445a44715457484654666d5f796867426779456c452d7234642d5a7150653974595971436e4176494c42755a6250597433554333664172394a6c7464554f353476784b626c6f327a3266642d48397a426e396a525a4f426b7556564238515356357372652d483233435442414253705a70653053724a705867473941755634446137465248424339412d6f4c594c652d5546355f3563365f636437635f4b51';

Your library gives me the following result"

0xb20b88288be511506c10693bee2576c8d431a58fd0922cb7cae31f638c299a73e57af9432804aeeae3ff086b9bcd38620479428580c336f61f3a2b565c3c29c5b27f32a99a8c0f9d0dbac8e4b7608322694a858f29384f27508a4614624572635c68ba1a0e937db611c2ed338b20e0659d76e4db33b8d3943b5a5cd6a1ae9f848f89fcd8ece63a06d003643a935871537e6ff2860060c84944fabe1df99a8f7bdb5862a0a702f20b06e65b3d8b77502ddf02bf4996d7543b9e2fc4a6e5a36cf67ddf87f73067f6345938192e55507c412579b2b7be1f6dc24c10014a96697b44ab2695e01bd02e5780daec5447042f40fa82d82def94179ff973afdc77b73f

It's almost correct, but the last 2 characters in the hex representation seem to be missing. I tried decoding the same value on https://cryptii.com/pipes/base64-to-hex and the result is almost the same. However, there are 2 extra characters 29 at the end.

image

So, I looked at your code and changed this line

// When decoding base64 string, 4 characters are converted back to 3 bytes, skip padding "="
uint256 decodedLength = (data.length / 4) * 3;

to this:

uint256 decodedLength = (data.length / 4) * 3 + 1;

This solved the issue for me. I'm not sure why this last byte was missing but I thought I'd let you know and leave this here just in case anyone else is having issues with this.

Again, thank you for providing this library! Really appreciate your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant