0

I try to compare value after encode base64 with string. But encode64 does not equal to Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU= Why does not it equal ?

import hashlib
hash_object = hashlib.sha256(b'Test')
hex_dig = hash_object.hexdigest()
encode64 = hex_dig.decode('hex').encode('base64')
print(encode64)
if encode64 == 'Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=' :
    print("Hello")

Output

Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=

It does not print Hello.

1
  • encode64 contains a newline, compare it with encode64.strip(). Commented May 29, 2017 at 6:53

1 Answer 1

3

There's a '\n' in the end of encode64 variable. You can do

if encode64.strip() == 'Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=' :
    print("Hello")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.