python base32 base64 编码解码

import base64
def base64encode(string):
    try:
        string = string.encode('utf-8')
        ans = base64.b64encode(string)
        ans = bytes.decode(ans)
    except:
        ans = ''
    return ans

def base64decode(string):
    try:
        string = string.encode()
        ans = base64.b64decode(string).decode('utf-8')
    except:
        ans = ''
    return ans

def base32encode(string):
    try:
        string = string.encode('utf-8')
        ans = base64.b32encode(string)
        ans = bytes.decode(ans)
    except:
        ans = ''
    return ans

def base32decode(string):
    try:
        string = string.encode()
        ans = base64.b32decode(string).decode('utf-8')
    except:
        ans = ''
    return ans
文章目录