1

I am using Cryptography Fernet for encryption and decryption. After encrypting data, it's length is to huge, is there any way to reduce it length or limit it?

Example : gAAAAABgUZeX2ffM7H07MfyZ2FGPj2xPSPbN0r3rQ1BzfKHsJ7QFUOgsqoOjOAh6Ksq-9fDCrLxb32g0NPbbU6F7lZeSk7Xfgj-2vHHtTjxd3rj02qWGoaQ=

def encrypt(message):
    encoded_message = message.encode()
    f = Fernet(app.config['SECRET_KEY'])
    encrypted_message = f.encrypt(encoded_message)

    return encrypted_message.decode()
Vaibhav Sawant
  • 341
  • 1
  • 7
  • 22
  • 120 bytes is *huge*? What are the constraints of your environment that require a smaller payload? If you can send arbitrary binary payloads then you can do away with the base64 encoding and shrink that 120 bytes down to 90. – President James K. Polk Mar 17 '21 at 12:00
  • Using a block cipher mode that requires padding will increase the size up to the next block boundary. Use CTR mode or similar to avoid the need for padding. Any mode with authentication, like GCM, will need extra space for the authentication data. A prepended IV will also increase the output size. Using Base64, as you appear to be doing, increases the final output size as @President James K. Polk pointed out. – rossum Mar 17 '21 at 12:19
  • GCM is CTR mode plus a MAC built in, so it already doesn't have data padding. There isn't really a secure way to not use an IV or not have integrity protection like with an AEAD or an added MAC, and honestly compared to HMAC an AEAD is going to be smaller. – bk2204 Mar 17 '21 at 22:53

0 Answers0