Skip to content

Commit

Permalink
Merge branch 'main' into passlib_addition
Browse files Browse the repository at this point in the history
  • Loading branch information
metamorphic-spyware committed May 24, 2022
2 parents 5377147 + 42cc05f commit f054472
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codacy-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: Codacy Security Scan

on:
push:
branches: [ main, passlib_addition]
branches: [ main, passlib_addition, fixes]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: "CodeQL"

on:
push:
branches: [ main, passlib_addition ]
branches: [ main, passlib_addition, fixes]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/devskim-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: DevSkim

on:
push:
branches: [ main, passlib_addition ]
branches: [ main, passlib_addition, fixes]
pull_request:
branches: [ main ]
schedule:
Expand Down
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,34 @@ After Following All The Steps Mentioned Above (If You Don't Get An Error) EnroCr
```python
# For Encryption
from enrocrypt import core
value = core.Encrypt(b'text')
obj = core.Core()
value = obj.Encrypt(b'text')
print(value)
# For Decryption
original_value = core.DecryptList(value)
original_value = obj.DecryptList(value)
print(original_value)
```
There Is Also a `Decrypt`Function, But In This Function You Have To Enter The Key And The Data Seperatly

## Adding Configurations
Enrocrypt Has The Ablity To Adopt Custom Configurations, Namely:- Custom Salt <br>
We Provide A Function In Which You Can Pass All The Configurations But It Also Has A Syntax And Must Be Used "As is"
```python
from enrocrypt import core
config = {
'configs':{
'salt_file':"The Path Of The File Where Your Salt Is Stored"
}
}
# You need a Core Class Object to access that function
obj = core.Core()
obj.set_config(config)
```
## Getting A Hashing Class Object
We Suggest Not To Use The Hashing Class By Importing It Directly As If You Do So You Can't Add Your Custom Salt <br>
To Add Custom Salt Follow The `Adding Configuration`. After You Did That You Have To Get A Hasing Class Object By A Core Class Function<br>
```python
from enrocrypt import core
obj = core.Core()
hasing_obj = obj.get_hash_object()
```
(See Discussion For More Info)
5 changes: 3 additions & 2 deletions enrocrypt/basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from enrocrypt import error
import uuid, os
from enrocrypt import error

class Basic():
'''This Class Consists of all the basic functions that can be useful'''
def __str__(self) -> str:
return "This Class Has All the Basic Functions Of EnroCrypt"
def seperator(self,data: str):
Expand Down Expand Up @@ -47,7 +48,7 @@ def to_str(self,data):
in_ascii.append(int(in_int[i],16))
for i,_ in enumerate(in_ascii):
in_str.append(chr(in_ascii[i]))
return(in_str)
return in_str

def Sign(self,sign:str):
'''A Hint Of Upcomming Updates'''
Expand Down
1 change: 1 addition & 0 deletions enrocrypt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __Set_Salt(self,salt:list):
else:
return False
def get_hash_object(self):
'''Returns A Hashing Class Object That Is Pre-Configured To Use Custom Salt If Any'''
hashing = Hashing()
if self.salt == "":
print(print(Warning("No Personalized Salt Loaded In The Memory, Using Random Salt")))
Expand Down
13 changes: 9 additions & 4 deletions enrocrypt/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ class ModifiedError(Exception):
def __init__(self):
self.msg = 'The List Provided To The Function Is Modified'
super().__init__(self.msg)
exit()
class ListIndexError(Exception):
def __init__(self):
self.msg = 'Returned List Must Only Have 4 Elements'
super().__init__(self.msg)
exit()
class NoKeyFile(Exception):
def __init__(self):
self.msg = 'No Path For The Key File was Provided'
super().__init__(self.msg)
exit()
class List(Exception):
def __init__(self):
self.msg = "Must Be A List"
super().__init__(self.msg)
def __init__(self):
self.msg = "Must Be A List"
super().__init__(self.msg)
exit()
class KeyError(Exception):
def __init__(self,bits:int) -> None:
self.bits = bits
self.msg = f"Key Must Be Of 32, 24 or 16 bits not {self.bits} bits"
super().__init__(self.msg)
super().__init__(self.msg)
exit()
54 changes: 25 additions & 29 deletions enrocrypt/hashing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hashlib, base64, uuid
import hashlib, base64, uuid, passlib
from cryptography.hazmat.primitives import hashes
from typing import Any
class Hashing():
Expand All @@ -10,26 +10,6 @@ def __call__(self, *args:Any):
def __str__(self):
return "Hashing Funcitions In Here"

def Standard_Multi_Hash(self,Data:str):
'''Inreversable Salted Hash Function Don't Use If U Want To Get The Content Back'''
a = hashlib.sha256(); a.update(bytes(Data.encode())); b = []
base = hashlib.sha512()
md = hashlib.md5()
b.append(str(a.digest()).split("'")[1])
b[0] = str(base64.urlsafe_b64encode(bytes(b[0].encode()))).split("'")[1]
base.update(bytes(b[0].encode()))
md.update(base.digest())
b[0]=str(base64.urlsafe_b64encode(base64.standard_b64encode(md.digest()))).split("'")[1]
salt = ['H', 'c', 'D', 'L', 'b', 'M', 'S', 'a', 'N', 'q', 'K', 'j', 'V', 'd', 'O', 'W', 'x']
c = (b[0].split("G"))or(b[0].split("g"))or(b[0].split("v"))or(b[0].split("x")); d=[]; e=[]
for i in range(len(c)): a = salt[i]; b = c[i]; c[i] = b+a
for i in range(len(c)):
try: d.append(c[i+1])
except: d.append(c[0])
e.append(''.join(d))
final = self.BLAKE2(bytes(str(e[0]).encode()))
return(final)

def __Salt(self,data,salt:bytes = None):
if not salt:
salts = []
Expand Down Expand Up @@ -57,16 +37,32 @@ def __Salt(self,data,salt:bytes = None):
if salting2 > self.byt:
salting2 = salting2.decode()[0:self.byt]
return salting2


def Standard_Multi_Hash(self,Data:str):
'''Inreversable Salted Hash Function Don't Use If U Want To Get The Content Back'''
a = hashlib.sha256(); a.update(bytes(Data.encode())); b = []
base = hashlib.sha512()
md = hashlib.md5()
b.append(str(a.digest()).split("'")[1])
b[0] = str(base64.urlsafe_b64encode(bytes(b[0].encode()))).split("'")[1]
base.update(bytes(b[0].encode()))
md.update(base.digest())
b[0]=str(base64.urlsafe_b64encode(base64.standard_b64encode(md.digest()))).split("'")[1]
salt = ['H', 'c', 'D', 'L', 'b', 'M', 'S', 'a', 'N', 'q', 'K', 'j', 'V', 'd', 'O', 'W', 'x']
c = (b[0].split("G"))or(b[0].split("g"))or(b[0].split("v"))or(b[0].split("x")); d=[]
d[0] = self.__Salt(c,salt=self.salt)
final = self.BLAKE2(bytes(str(d[0]).encode()))
return(final)

def SHA256(self,data:str):
sha = hashlib.sha256(bytes(data.encode()))
hash = sha.digest()
return self.__Salt(hash,salt=self.salt)
Hash = sha.digest()
return self.__Salt(Hash,salt=self.salt)

def SHA512(self,data:str):
sha = hashlib.sha512(bytes(data.encode()))
hash = str(sha.digest())
return self.__Salt(hash,salt=self.salt)
Hash = str(sha.digest())
return self.__Salt(Hash,salt=self.salt)

def SHA244(self,data:str):
sha = hashlib.sha224(bytes(data.encode()))
Expand All @@ -75,10 +71,10 @@ def SHA244(self,data:str):

def SHA384(self,data:str):
sha = hashlib.sha384(bytes(data.encode()))
hash = str(sha.digest())
return self.__Salt(hash,salt=self.salt)
Hash = str(sha.digest())
return self.__Salt(Hash,salt=self.salt)

def BLAKE2(self,data:bytes):
a = hashes.Hash(hashes.BLAKE2s(32))
a.update(data)
return self.__Salt(a.finalize(),salt=self.salt)
return self.__Salt(a.finalize(),salt=self.salt)
1 change: 0 additions & 1 deletion enrocrypt/key.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from cryptography.hazmat.primitives.hashes import SHA256
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from enrocrypt.hashing import Hashing
from enrocrypt.encryption import Encryption
from enrocrypt.error import KeyError

def generate_key(words:str,salt:bytes,bits:int = 32):
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
file = open('README.md','r').read()
setup(
name="enrocrypt",
version="1.1.3",
version="1.1.4",
author="Morgan-Phoenix",
author_email="mikebrain61@gmail.com",
description="This is a Python Module For Encryption, Hashing And Other stuff",
long_description=file,
long_description_content_type="text/markdown",
Expand All @@ -18,6 +17,6 @@
"Operating System :: OS Independent",
],
packages=find_packages(),
install_requires=['cryptography'],
install_requires=['cryptography', 'passlib'],
python_requires=">=3.6",
)

0 comments on commit f054472

Please sign in to comment.