From f9137272dda85f02b7733188e2426030e970be60 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Thu, 19 Sep 2024 09:18:02 +0200 Subject: [PATCH] material digital presentation --- book/0-get_open_ai_token.ipynb | 1 + 1 file changed, 1 insertion(+) create mode 100644 book/0-get_open_ai_token.ipynb diff --git a/book/0-get_open_ai_token.ipynb b/book/0-get_open_ai_token.ipynb new file mode 100644 index 0000000..6fa4c45 --- /dev/null +++ b/book/0-get_open_ai_token.ipynb @@ -0,0 +1 @@ +{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3 (ipykernel)","language":"python"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":5,"nbformat":4,"cells":[{"id":"140cd709-3deb-4886-b2a5-10ec1d8eb689","cell_type":"markdown","source":"# Get your OpenAI token\nThis token is only active during the workshop session this morning. ","metadata":{}},{"id":"e2e98a7c-8b5a-4e65-9070-ad59c1621d60","cell_type":"code","source":"import base64\nimport os\nfrom cryptography.fernet import Fernet\nfrom cryptography.hazmat.primitives import hashes\nfrom cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC\nfrom getpass import getpass","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"b00228c4-e4d9-4e20-82ed-f4593cf7dae7","cell_type":"code","source":"password = getpass(prompt='Enter your Password:').encode()\nsalt = b'\\x86;e\\x8e\\nr\\xe7I\\xcb\\x924[\\xd5\\xf8o/'\nkdf = PBKDF2HMAC(\n algorithm=hashes.SHA256(),\n length=32,\n salt=salt,\n iterations=480000,\n)\nkey = base64.urlsafe_b64encode(kdf.derive(password))\nf = Fernet(key)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"679f7f96-cfab-41a0-ac50-77f56e2839d3","cell_type":"code","source":"encrypted_data = 'gAAAAABm687lC-BFZEzabcDPgl9t_i8pW9IbAkYLHzTv1A_ivpIHpNTHBy83JZ2k1i_YxLAf7mvirIJuuh7zloij9acQjFRK9HZGBclvVFZrY9-u7oCPpFJ_DpBTPg8kywZOsvoIjRp4JlwGTA0utrkQiHyWVneVMZO1ZtpGWBW-Mo8nuA9yEhkkAyRVDH-J3BsflqMuovZw'","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"d5c2c62c-b058-482f-90df-b3c5fa8d9a8a","cell_type":"markdown","source":"## Copy your OpenAI token below","metadata":{}},{"id":"4b624977-6034-47a6-9957-f93c51d7e8dc","cell_type":"code","source":"f.decrypt(encrypted_data.encode()).decode()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"cff9f747-8c05-4bbc-b921-d6d29e51a2f1","cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]} \ No newline at end of file