LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2019, 12:54 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Python Encryption Of User Input


Gents,

I am in the process of creating a Python program that will use an API-Key to access a REST API on a particular website to perform certain actions. I do not want to store this API-Key inside the program as it would be insecure. My thinking is to prompt the user for the API-Key before the program executes as in:
Code:
import requests
from cryptography.fernet import Fernet

key = Fernet.generate_key()
priv_key = Fernet(key)

cap = input(b"Please Provide your API-Key: ").encode()

enc_input = priv_key.encrypt(cap)

base_vt = "https://www.blahblahblah.com/v3/"
req_head = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'}
vt_persist = requests.sessions()
vt_persist.headers.update(req_head)

get_real_goodies = vt_persist.get(base_vt + priv_key.decrypt(enc_input).decode())
Looking at this from a security perspective, I see many wholes in my logic and wanted some feedback from the Linux Gods.

Last edited by metallica1973; 10-28-2019 at 10:17 AM.
 
Old 10-27-2019, 11:09 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,862

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
What kind of whole do you see?
did you try this code? Is this what you really need? I don't really understand what do you want to achieve.
 
Old 10-28-2019, 10:09 AM   #3
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Hello Pan64 and thank you for your reply. What I am trying to achieve is the best secure coding practice when it comes to storing/handling API keys and or passwords inside my code and or scripts. I want to minimize the chances of giving the bad guys the keys to the kingdom. With that being said, in a previous job that I had, there was a password management application that we used that provided a webservice that used Integrated Windows Authentication that we would call using its REST API for creds instead of a user name and password. Simply put, if the system in which the code ran on, had a valid windows service account and a valid account on the password management server, it worked rather well. This was used in our dev environments for our in-house applications and for our scripts. Unfortunately in my current environment, I don't have that luxury and wanted to pick the forums mind to see if I could get a different perspective on this or to tell me that I am crazy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I got error while installing python-tk python-psycopg2 python-twisted saili kadam Linux - Newbie 1 09-05-2015 03:03 AM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
User input into Bash scripts and checking validity of user input?? helptonewbie Programming 8 07-07-2008 06:40 PM
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 08:35 AM
Mandrake 9.0 Wireless Works without encryption.. does not with encryption topcat Linux - Wireless Networking 3 05-04-2003 08:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration