Error decoding incorrect paddling with decode64, with padding present?
up vote
-2
down vote
favorite
With the code that I am using, every time there is a "?
" on data of the encoded message I get an error back "Incorrect Padding"
. When using a decoder online I get the correct value for both value1
and value2
below, but for value2
where there should be a "?"
I get an exception instead.
The code is:
value1 = "Y29udGludWENCg=="
expected1 = b'continuarn'
value2 = "Y29udGludWE_DQo="
expected2 = b'continua?rn'
data1 = base64.b64decode(value1)
assert data1 == expected1
data2 = base64.b64decode(value2)
assert data2 == expected2
Decoding value2
throws a binascii.Error: Incorrect padding
exception, but the data has the right amount of padding (the length of value2
is a multiple of 4).
python base64 decode
add a comment |
up vote
-2
down vote
favorite
With the code that I am using, every time there is a "?
" on data of the encoded message I get an error back "Incorrect Padding"
. When using a decoder online I get the correct value for both value1
and value2
below, but for value2
where there should be a "?"
I get an exception instead.
The code is:
value1 = "Y29udGludWENCg=="
expected1 = b'continuarn'
value2 = "Y29udGludWE_DQo="
expected2 = b'continua?rn'
data1 = base64.b64decode(value1)
assert data1 == expected1
data2 = base64.b64decode(value2)
assert data2 == expected2
Decoding value2
throws a binascii.Error: Incorrect padding
exception, but the data has the right amount of padding (the length of value2
is a multiple of 4).
python base64 decode
Your base64 padding is indeed invalid. It can be repaired, which is what an online decoder might have done.
– Martijn Pieters♦
Nov 20 at 8:21
Just add the missing'='
. Remove all non-Base64 characters first, then if the length is not a multiple of 4, add=
characters until it is.
– Martijn Pieters♦
Nov 20 at 8:23
could you show me a exemple martijn?
– joao santana
Nov 20 at 8:26
Ah, I see what is going on: You have URL-safe data. Usebase64.urlsafe_b64decode()
.
– Martijn Pieters♦
Nov 20 at 8:35
In future, start with a complete Minimal, Complete, and Verifiable example; I've filled in the blanks here once I figured out what kind of data you were expecting. Don't leave people trying to help you to guess.
– Martijn Pieters♦
Nov 20 at 10:33
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
With the code that I am using, every time there is a "?
" on data of the encoded message I get an error back "Incorrect Padding"
. When using a decoder online I get the correct value for both value1
and value2
below, but for value2
where there should be a "?"
I get an exception instead.
The code is:
value1 = "Y29udGludWENCg=="
expected1 = b'continuarn'
value2 = "Y29udGludWE_DQo="
expected2 = b'continua?rn'
data1 = base64.b64decode(value1)
assert data1 == expected1
data2 = base64.b64decode(value2)
assert data2 == expected2
Decoding value2
throws a binascii.Error: Incorrect padding
exception, but the data has the right amount of padding (the length of value2
is a multiple of 4).
python base64 decode
With the code that I am using, every time there is a "?
" on data of the encoded message I get an error back "Incorrect Padding"
. When using a decoder online I get the correct value for both value1
and value2
below, but for value2
where there should be a "?"
I get an exception instead.
The code is:
value1 = "Y29udGludWENCg=="
expected1 = b'continuarn'
value2 = "Y29udGludWE_DQo="
expected2 = b'continua?rn'
data1 = base64.b64decode(value1)
assert data1 == expected1
data2 = base64.b64decode(value2)
assert data2 == expected2
Decoding value2
throws a binascii.Error: Incorrect padding
exception, but the data has the right amount of padding (the length of value2
is a multiple of 4).
python base64 decode
python base64 decode
edited Nov 20 at 10:32
Martijn Pieters♦
695k12924052245
695k12924052245
asked Nov 20 at 8:18
joao santana
45
45
Your base64 padding is indeed invalid. It can be repaired, which is what an online decoder might have done.
– Martijn Pieters♦
Nov 20 at 8:21
Just add the missing'='
. Remove all non-Base64 characters first, then if the length is not a multiple of 4, add=
characters until it is.
– Martijn Pieters♦
Nov 20 at 8:23
could you show me a exemple martijn?
– joao santana
Nov 20 at 8:26
Ah, I see what is going on: You have URL-safe data. Usebase64.urlsafe_b64decode()
.
– Martijn Pieters♦
Nov 20 at 8:35
In future, start with a complete Minimal, Complete, and Verifiable example; I've filled in the blanks here once I figured out what kind of data you were expecting. Don't leave people trying to help you to guess.
– Martijn Pieters♦
Nov 20 at 10:33
add a comment |
Your base64 padding is indeed invalid. It can be repaired, which is what an online decoder might have done.
– Martijn Pieters♦
Nov 20 at 8:21
Just add the missing'='
. Remove all non-Base64 characters first, then if the length is not a multiple of 4, add=
characters until it is.
– Martijn Pieters♦
Nov 20 at 8:23
could you show me a exemple martijn?
– joao santana
Nov 20 at 8:26
Ah, I see what is going on: You have URL-safe data. Usebase64.urlsafe_b64decode()
.
– Martijn Pieters♦
Nov 20 at 8:35
In future, start with a complete Minimal, Complete, and Verifiable example; I've filled in the blanks here once I figured out what kind of data you were expecting. Don't leave people trying to help you to guess.
– Martijn Pieters♦
Nov 20 at 10:33
Your base64 padding is indeed invalid. It can be repaired, which is what an online decoder might have done.
– Martijn Pieters♦
Nov 20 at 8:21
Your base64 padding is indeed invalid. It can be repaired, which is what an online decoder might have done.
– Martijn Pieters♦
Nov 20 at 8:21
Just add the missing
'='
. Remove all non-Base64 characters first, then if the length is not a multiple of 4, add =
characters until it is.– Martijn Pieters♦
Nov 20 at 8:23
Just add the missing
'='
. Remove all non-Base64 characters first, then if the length is not a multiple of 4, add =
characters until it is.– Martijn Pieters♦
Nov 20 at 8:23
could you show me a exemple martijn?
– joao santana
Nov 20 at 8:26
could you show me a exemple martijn?
– joao santana
Nov 20 at 8:26
Ah, I see what is going on: You have URL-safe data. Use
base64.urlsafe_b64decode()
.– Martijn Pieters♦
Nov 20 at 8:35
Ah, I see what is going on: You have URL-safe data. Use
base64.urlsafe_b64decode()
.– Martijn Pieters♦
Nov 20 at 8:35
In future, start with a complete Minimal, Complete, and Verifiable example; I've filled in the blanks here once I figured out what kind of data you were expecting. Don't leave people trying to help you to guess.
– Martijn Pieters♦
Nov 20 at 10:33
In future, start with a complete Minimal, Complete, and Verifiable example; I've filled in the blanks here once I figured out what kind of data you were expecting. Don't leave people trying to help you to guess.
– Martijn Pieters♦
Nov 20 at 10:33
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You do not have standard Base64 data, you have URL-safe base64 data.
Base64 normally uses letters, digits and /
and +
characters, but the latter two carry special meaning in URLs, so an alternative Base64url encoding is used that uses -
and _
characters instead.
Use the base64.urlsafe_b64decode()
function to decode these strings:
data2 = base64.urlsafe_b64decode(value2)
Demo:
>>> import base64
>>> value2 = "Y29udGludWE_DQo="
>>> base64.urlsafe_b64decode(value2)
b'continua?rn'
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You do not have standard Base64 data, you have URL-safe base64 data.
Base64 normally uses letters, digits and /
and +
characters, but the latter two carry special meaning in URLs, so an alternative Base64url encoding is used that uses -
and _
characters instead.
Use the base64.urlsafe_b64decode()
function to decode these strings:
data2 = base64.urlsafe_b64decode(value2)
Demo:
>>> import base64
>>> value2 = "Y29udGludWE_DQo="
>>> base64.urlsafe_b64decode(value2)
b'continua?rn'
add a comment |
up vote
0
down vote
accepted
You do not have standard Base64 data, you have URL-safe base64 data.
Base64 normally uses letters, digits and /
and +
characters, but the latter two carry special meaning in URLs, so an alternative Base64url encoding is used that uses -
and _
characters instead.
Use the base64.urlsafe_b64decode()
function to decode these strings:
data2 = base64.urlsafe_b64decode(value2)
Demo:
>>> import base64
>>> value2 = "Y29udGludWE_DQo="
>>> base64.urlsafe_b64decode(value2)
b'continua?rn'
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You do not have standard Base64 data, you have URL-safe base64 data.
Base64 normally uses letters, digits and /
and +
characters, but the latter two carry special meaning in URLs, so an alternative Base64url encoding is used that uses -
and _
characters instead.
Use the base64.urlsafe_b64decode()
function to decode these strings:
data2 = base64.urlsafe_b64decode(value2)
Demo:
>>> import base64
>>> value2 = "Y29udGludWE_DQo="
>>> base64.urlsafe_b64decode(value2)
b'continua?rn'
You do not have standard Base64 data, you have URL-safe base64 data.
Base64 normally uses letters, digits and /
and +
characters, but the latter two carry special meaning in URLs, so an alternative Base64url encoding is used that uses -
and _
characters instead.
Use the base64.urlsafe_b64decode()
function to decode these strings:
data2 = base64.urlsafe_b64decode(value2)
Demo:
>>> import base64
>>> value2 = "Y29udGludWE_DQo="
>>> base64.urlsafe_b64decode(value2)
b'continua?rn'
edited Nov 20 at 10:37
answered Nov 20 at 8:37
Martijn Pieters♦
695k12924052245
695k12924052245
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388786%2ferror-decoding-incorrect-paddling-with-decode64-with-padding-present%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your base64 padding is indeed invalid. It can be repaired, which is what an online decoder might have done.
– Martijn Pieters♦
Nov 20 at 8:21
Just add the missing
'='
. Remove all non-Base64 characters first, then if the length is not a multiple of 4, add=
characters until it is.– Martijn Pieters♦
Nov 20 at 8:23
could you show me a exemple martijn?
– joao santana
Nov 20 at 8:26
Ah, I see what is going on: You have URL-safe data. Use
base64.urlsafe_b64decode()
.– Martijn Pieters♦
Nov 20 at 8:35
In future, start with a complete Minimal, Complete, and Verifiable example; I've filled in the blanks here once I figured out what kind of data you were expecting. Don't leave people trying to help you to guess.
– Martijn Pieters♦
Nov 20 at 10:33