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

Encode plaintext before padding it #4527

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions st2common/st2common/util/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def cryptography_symmetric_encrypt(encrypt_key, plaintext):
assert isinstance(aes_key_bytes, six.binary_type)
assert isinstance(hmac_key_bytes, six.binary_type)

# Convert data to bytes
if isinstance(plaintext, (six.text_type, six.string_types)):
plaintext = plaintext.encode('utf-8')

# Pad data
data = pkcs5_pad(plaintext)

Expand All @@ -229,11 +233,6 @@ def cryptography_symmetric_encrypt(encrypt_key, plaintext):
# NOTE: We don't care about actual Keyczar header value, we only care about the length (5
# bytes) so we simply add 5 0's
header_bytes = b'00000'

if isinstance(data, (six.text_type, six.string_types)):
# Convert data to bytes
data = data.encode('utf-8')

ciphertext_bytes = encryptor.update(data) + encryptor.finalize()
msg_bytes = header_bytes + iv_bytes + ciphertext_bytes

Expand Down