Obfuscate strings in Python

后端 未结 6 1368
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 08:54

I have a password string that must be passed to a method. Everything works fine but I don\'t feel comfortable storing the password in clear text. Is there a way to obfuscate

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-02 09:34

    If you just want to prevent casually glancing at a password, you may want to consider encoding/decoding the password to/from base64. It's not secure in the least, but the password won't be casually human/robot readable.

    import base64
    # Encode password (must be bytes type)
    encoded_pw = base64.b64encode(raw_pw)
    
    # Decode password (must be bytes type)
    decoded_pw = base64.b64decode(encoded_pw)
    

提交回复
热议问题