Check if a string is encoded in base64 using Python

前端 未结 10 2053
离开以前
离开以前 2021-02-05 01:56

Is there a good way to check if a string is encoded in base64 using Python?

10条回答
  •  后悔当初
    2021-02-05 02:24

    Using Python RegEx

    import re
    
    txt = "VGhpcyBpcyBlbmNvZGVkIHRleHQ="
    x = re.search("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$", txt)
    
    if (x):
      print("Encoded")
    else:
      print("Non encoded")
    

提交回复
热议问题