Is it ok to remove the equal signs from a base64 string?

前端 未结 6 1125
眼角桃花
眼角桃花 2021-02-02 10:05

I have a string that I\'m encoding into base64 to conserve space. Is it a big deal if I remove the equal sign at the end? Would this significantly decrease entropy? What can I d

6条回答
  •  耶瑟儿~
    2021-02-02 10:41

    Other than in the case @Martin Ellis points out, messing with the padding characters can lead to getting a

    TypeError: Incorrect padding
    

    and And producing some garbage while you're at it.

    As stated by @MattH, base64 will do the opposite of conserving space.

    Instead to conserve space, you should apply compression algorithms such as zlib.

    For example, zlib

    import zlib
    
    s = '''large string....'''
    compressed = zlib.compress(s)
    
    compression_ratio = len(s)*1.0/len(compressed)    
    
    # And later...
    out = zlib.decompress(compressed) 
    
    # The above function is also good for relieving stress.
    

提交回复
热议问题