Remove trailing “=” when base64 encoding

前端 未结 9 2027
时光取名叫无心
时光取名叫无心 2020-11-29 23:58

I am noticing that whenever I base64 encode a string, a \"=\" is appended at the end. Can I remove this character and then reliably decode it later by adding it back, or is

9条回答
  •  -上瘾入骨i
    2020-11-30 00:16

    Using Python you can remove base64 padding and add it back like this:

    from math import ceil
    
    stripped = original.rstrip('=')
    
    original = stripped.ljust(ceil(len(stripped) / 4) * 4, '=')
    

提交回复
热议问题