Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7620f3a

Browse files
Updating readme with new discoveries about obfuscation
1 parent 1314937 commit 7620f3a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

β€ŽREADME.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,74 @@ def createItem(item_id: int, item: Item):
654654
return inventoryDict[str(item_id)]
655655
```
656656

657+
658+
<h3>Key Obfuscation</h3>
659+
<p>Obfuscation is the deliberate act of creating source or machine code that is difficult for humans to understand, this helps to improve security - it is far from being the ultimate security solution but is a thing to use in a non-production environment.</p>
660+
661+
For creating a file with the key and obfuscating it:
662+
663+
```python
664+
import base64
665+
import pathlib
666+
import os
667+
import re
668+
from pathlib import Path
669+
670+
# Dynamic File Path Solution
671+
API_PATH = pathlib.Path(__file__).parent.absolute()
672+
673+
674+
def relative_to_assets(path: str) -> Path:
675+
return API_PATH / Path(path)
676+
677+
userChange = input("Enter key: ").strip()
678+
679+
# Pick userChange and encode it to base64
680+
userChange = base64.b64encode(userChange.encode('utf-8'))
681+
# Save userChange to "API" file
682+
with open(relative_to_assets('Data/security/API'), 'wb') as f:
683+
# Delete everything inside the file.
684+
f.truncate()
685+
f.write(userChange)
686+
687+
print("DONE! You are ready to use the API!")
688+
689+
```
690+
691+
692+
For reading Key from file:
693+
694+
```python
695+
import base64
696+
import pathlib
697+
import os
698+
import re
699+
from pathlib import Path
700+
701+
# Dynamic File Path Solution
702+
API_PATH = pathlib.Path(__file__).parent.absolute()
703+
704+
705+
def relative_to_assets(path: str) -> Path:
706+
return API_PATH / Path(path)
707+
708+
API_CONTENT = None
709+
# πŸ” Security execution => READING API FROM FILE
710+
711+
712+
def API_SEC():
713+
global API_CONTENT
714+
# Security measures
715+
API_CONTENT = open(relative_to_assets("Data/security/API"), "r").read()
716+
API_DECODED = base64.b64decode(API_CONTENT.encode("utf-8"))
717+
718+
# Regular expression to remove garbage characters, do not remove "-"
719+
API_DECODED_CLEAN = re.sub(
720+
r"[^A-Za-z0-9-]", "", API_DECODED.decode("utf-8"))
721+
722+
return API_DECODED_CLEAN
723+
```
724+
657725
## πŸ“„ License
658726

659727
Permissions of this strong copyleft license are conditioned on making available complete source code of licensed works and modifications, which include larger works using a licensed work, under the same license. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights.

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /