Search code examples
pythonencryptionsftppysftp

How to encrypt password in Python pysftp?


I am using a Python script with the pysftp module to connect to SFTP server.

Apparently I can pass a SFTP password explicitly which I don't like.

My question: How could I replace the password for an encrypted one to avoid someone from being visible to the world?


Solution

  • I found the solution for this issue. It works for me. Instead of using explicit text of password I first encode it and put incoded form into the script.

    Like this:

    import base64
    
    ## To encrypt:
    base64.b64encode("XYZ")
    ## you got 'WFla'
    
    ## To decrypt:
    base64.b64decode("WFla")
    # you got 'XYZ'