Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

94
Views
Trying to convert Javascript AES encryption to Python

I'm trying to convert the following Javascript code to python:

cryptoJs.AES.encrypt("secrettext", cryptoJs.enc.Base64.parse("QWJjZGVmZ2hpamtsbW5vcA=="), { iv: cryptoJs.enc.Base64.parse("AAAAAAAAAAAAAAAAAAAAAA==")}).ciphertext.toString(cryptoJs.enc.Base64)

I've been trying to figure out the python equivalent of the different parts (key and iv), but nothing is working. This is what I last tried but was given an error that my IV was the incorrect length:

key = b"QWJjZGVmZ2hpamtsbW5vcA=="
iv = b"AAAAAAAAAAAAAAAAAAAAAA=="
text = b"secrettext"

base64_key = base64.b64encode(key)
base64_iv = base64.b64encode(iv)

padtext=pad(text,16,style='pkcs7')

encryptor = AES.new(base64_key, AES.MODE_CBC, base64_iv)
result = encryptor.encrypt(padtext)
print(binascii.hexlify(result))
7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.