DE-Lib 0.0.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. DE_Lib/Cloud/__init__.py +0 -0
  2. DE_Lib/DataBase/Azure.py +44 -0
  3. DE_Lib/DataBase/Cache.py +74 -0
  4. DE_Lib/DataBase/Firebird.py +45 -0
  5. DE_Lib/DataBase/Informix.py +37 -0
  6. DE_Lib/DataBase/Metadata.py +62 -0
  7. DE_Lib/DataBase/MsSql.py +39 -0
  8. DE_Lib/DataBase/MySql.py +42 -0
  9. DE_Lib/DataBase/Oracle.py +111 -0
  10. DE_Lib/DataBase/Postgres.py +39 -0
  11. DE_Lib/DataBase/RedShift.py +42 -0
  12. DE_Lib/DataBase/SQCipher.py +42 -0
  13. DE_Lib/DataBase/SQLite.py +48 -0
  14. DE_Lib/DataBase/__init__.py +0 -0
  15. DE_Lib/Files/Avro.py +23 -0
  16. DE_Lib/Files/Csv.py +64 -0
  17. DE_Lib/Files/JSon.py +64 -0
  18. DE_Lib/Files/Parquet.py +31 -0
  19. DE_Lib/Files/Txt.py +64 -0
  20. DE_Lib/Files/Xlsx.py +55 -0
  21. DE_Lib/Files/__init__.py +0 -0
  22. DE_Lib/Log/DE_LogEventos.py +533 -0
  23. DE_Lib/Log/Level.py +77 -0
  24. DE_Lib/Log/Log.py +470 -0
  25. DE_Lib/Log/__init__.py +0 -0
  26. DE_Lib/Utils/Cipher/Aes.py +65 -0
  27. DE_Lib/Utils/Cipher/Argon.py +37 -0
  28. DE_Lib/Utils/Cipher/Base64.py +48 -0
  29. DE_Lib/Utils/Cipher/Cipher.py +300 -0
  30. DE_Lib/Utils/Cipher/Fernet.py +81 -0
  31. DE_Lib/Utils/Cipher/Gcm.py +78 -0
  32. DE_Lib/Utils/Cipher/Pbkdf2.py +43 -0
  33. DE_Lib/Utils/Cipher/Rsa.py +140 -0
  34. DE_Lib/Utils/Cipher/__init__.py +0 -0
  35. DE_Lib/Utils/Colors.py +203 -0
  36. DE_Lib/Utils/DateUtils.py +215 -0
  37. DE_Lib/Utils/Generic.py +249 -0
  38. DE_Lib/Utils/SQL.py +34 -0
  39. DE_Lib/Utils/System.py +50 -0
  40. DE_Lib/Utils/WebHook.py +18 -0
  41. DE_Lib/Utils/__init__.py +0 -0
  42. DE_Lib/__init__.py +0 -0
  43. de_lib-0.0.20.dist-info/LICENCE +21 -0
  44. de_lib-0.0.20.dist-info/METADATA +68 -0
  45. de_lib-0.0.20.dist-info/RECORD +47 -0
  46. de_lib-0.0.20.dist-info/WHEEL +5 -0
  47. de_lib-0.0.20.dist-info/top_level.txt +1 -0
DE_Lib/Log/Log.py ADDED
@@ -0,0 +1,470 @@
1
+ #region Imports
2
+ import sys
3
+
4
+ from source.Log import Level as LVL
5
+ from source.DataBase import SQLite as SLT
6
+ from source.Utils import DateUtils as DTU
7
+ from source.Utils import Generic as GEN
8
+ from source.Utils import System as SOP
9
+ from source.Utils import Colors as COR
10
+ import inspect
11
+ import os
12
+ import json
13
+ import datetime as dt
14
+ #endregion
15
+
16
+ #region Instancias
17
+ lvl = LVL.Level() # biblioteca LOG - Trata os niveis do log
18
+ slt = SLT.SQLite() # biblioteca DataBase - Driver SQLite
19
+ dtu = DTU.DateUtils() # bibliotaca Utils.DateUtils - Tratamento de dadas
20
+ gen = GEN.Generic() # biblioteda Utils.Generic - diversas funcionalidades
21
+ sop = SOP.SO() # biblioteca Utils.SO - Diversar funcoes do sistema operacional
22
+ cor = COR.Colors() # biblioteca Utils.Colors - represantação de cores (utilizada na LOG)
23
+ #endregion
24
+
25
+
26
+ class Log:
27
+ def __init__(self):
28
+ self.__processo = None
29
+ self.__list_log_detail = []
30
+ self.__log_header = None
31
+
32
+ #region Inicializacao, Registro de Evento e Finalizacao do LOG
33
+ def setInit(self, processo: dict):
34
+ msg, result = None, True
35
+ try:
36
+ self.__processo = processo
37
+ self.__call_origin = self.__getCALLFUNCTION()
38
+ self.__log_header = self.__setLogHeader()
39
+ print(self.__setPrintInicializacao())
40
+ except Exception as error:
41
+ msg = error
42
+ result = result + msg
43
+ finally:
44
+ return result
45
+
46
+ # ----------------------------------
47
+ def setLogEvent(self, content: str, level=lvl.NOTSET, color: str = "", lf: bool = True, onscreen: bool = True):
48
+ msg, result = None, True
49
+ try:
50
+ self.__setLogDetail(content=content, level=level)
51
+ self.__setPrintScreen(level=level)
52
+ except Exception as error:
53
+ msg = error
54
+ result = msg
55
+ finally:
56
+ return result
57
+
58
+ # ----------------------------------
59
+ def setEnd(self):
60
+ msg, result = None, True
61
+ try:
62
+
63
+ __log = self.LOG_HEADER
64
+ __log["event_content"]= self.LOG_DETAIL
65
+ self.__log_header = __log
66
+
67
+ fh = open(self.FILELOG, "w")
68
+ buf = fh.write(json.dumps(self.LOG_HEADER, indent=4))
69
+ fh.close()
70
+ print(self.__setPrintFinalizacao())
71
+
72
+ rst = self.setInsertLOG()
73
+ print(rst)
74
+ rst = self.setInsertEVENT()
75
+ print(rst)
76
+
77
+ #print(json.dumps(__log, indent=4))
78
+ except Exception as error:
79
+ msg = error
80
+ result = msg
81
+ finally:
82
+ return result
83
+ #endregion
84
+
85
+ #region Estrutura do Header e Evento do LOG
86
+ # ----------------------------------
87
+ def __setLogHeader(self):
88
+ msg, result = None, True
89
+ try:
90
+ __header = {"hash": gen.build_key(),
91
+ "nom_rotina": self.PROCESSO["processo"],
92
+ "nom_subrotina": self.CALL_FUNCTION,
93
+ "descricao": self.PROCESSO["descricao"],
94
+ "file": self.FILELOG,
95
+ "user_db": "",
96
+ "os_user": sop.OSINFO["os_user"],
97
+ "local_ip": sop.OSINFO["local_ip"],
98
+ "local_name": sop.OSINFO["local_name"],
99
+ "processor": sop.OSINFO["processor"],
100
+ "so_platform": sop.OSINFO["so_platform"],
101
+ "so_system": sop.OSINFO["so_system"],
102
+ "so_version": sop.OSINFO["so_version"],
103
+ "timestamp": dt.datetime.now().strftime(dtu.MILLISECONDS_FORMAT_PYTHON),
104
+ "versao": sop.OSINFO["so_version"]
105
+ }
106
+ result = __header
107
+ except Exception as error:
108
+ msg = error
109
+ result = msg
110
+ finally:
111
+ return result
112
+
113
+ def __setLogDetail(self, level, content):
114
+ msg, result = None, True
115
+ try:
116
+ __detail = {"hash": gen.build_key(),
117
+ "hash_parent": self.LOG_HEADER["hash"],
118
+ "timestamp": dt.datetime.now().strftime(dtu.MILLISECONDS_FORMAT_PYTHON),
119
+ "level_code": level["code"],
120
+ "level_name": level["name"],
121
+ "function_name": self.CALL_FUNCTION,
122
+ "func_line": self.CALL_LINE,
123
+ "func_index": self.CALL_INDEX,
124
+ "code_context": self.CALL_CONTEXT,
125
+ "code_file": self.CALL_FILE,
126
+ "event_content": content
127
+ }
128
+ self.__list_log_detail.append(__detail)
129
+ except Exception as error:
130
+ msg = error
131
+ result = msg
132
+ finally:
133
+ return result
134
+ #endregion
135
+
136
+ #region Set PRINT
137
+ # ----------------------------------
138
+ def __setPrintInicializacao(self):
139
+ msg, result = None, True
140
+ try:
141
+ size = len(max(self.LOG_HEADER.values(), key=len)) + 21
142
+ sep = cor.green_fore + "#" + "-" * size + "#" + cor.reset + "\n"
143
+ data = []
144
+ for key in self.LOG_HEADER:
145
+ h = cor.green_fore + "# " + cor.reset + cor.red_fore + key + cor.reset + " " + "." * (15-len(str(key))) + " : " + cor.yellow_fore + self.LOG_HEADER[key] + cor.reset + " " * (size-21-len(self.LOG_HEADER[key])) + cor.green_fore + " #" + cor.reset
146
+ data.append(h)
147
+
148
+ result = sep
149
+ for n in data:
150
+ result = result + n + "\n"
151
+ result = result + sep
152
+
153
+ except Exception as error:
154
+ msg = error
155
+ result = msg
156
+ finally:
157
+ return result
158
+
159
+ # ----------------------------------
160
+ def __setPrintFinalizacao(self):
161
+ msg, result = None, True
162
+ try:
163
+ size = len(max(self.LOG_HEADER.values(), key=len)) + 21
164
+ sep = cor.green_fore + "#" + "-" * size + "#" + cor.reset + "\n"
165
+ result = sep
166
+ result = result + f"Log Finalizado - {dt.datetime.now().strftime(dtu.MILLISECONDS_FORMAT_PYTHON)}\n"
167
+ result = result + f"Tamanho em memoria do LOG: {gen.DictSizeBytes(self.LOG_HEADER)} bytes\n"
168
+ result = result + sep
169
+
170
+ except Exception as error:
171
+ msg = error
172
+ result = msg
173
+ finally:
174
+ return result
175
+ #endregion
176
+
177
+ # region Print LOG
178
+ def __setPrintScreen(self, level, lf: bool = True, onscreen: bool = True):
179
+ if onscreen:
180
+ __log = self.LOG_DETAIL[-1]
181
+ __text = f"""{cor.reset}{__log["timestamp"]}-{level["color"]}{__log["level_name"].ljust(10)}{cor.reset}: {level["color"]}{__log["event_content"]}{cor.reset}"""
182
+ if lf:
183
+ print(__text)
184
+ else:
185
+ print(__text, end="")
186
+
187
+ def __setPrintFile(self, logger, msg):
188
+ logger.write(msg)
189
+ # endregion
190
+
191
+ #region SET´s Metodos
192
+ def __setDeviceFile(self):
193
+ msg, result = None, True
194
+ try:
195
+ # Foi passado um nome de arquivo de log
196
+ if self.PROCESSO["file"] is None:
197
+ if not os.path.isdir(os.path.dirname(self.FILELOG)):
198
+ # se o diretorio informado não existir sera utilizado o diretorio local
199
+ if os.path.basename(self.FILELOG) is None:
200
+ self.__setFileName(os.path.join(os.getcwd(), self.PROCESSO), ".json")
201
+ else:
202
+ self.__setFileName(os.path.join(os.getcwd(), self.PROCESSO["processo"], ".json"))
203
+ # Criando um File Handle para o arquivo informado
204
+ result = open(self.FILELOG, "w", encoding='utf-8')
205
+ except Exception as error:
206
+ msg = error
207
+ result = msg
208
+ finally:
209
+ return result
210
+
211
+ def __getCALLFUNCTION(self, value = inspect.stack()):
212
+ msg, result = None, True
213
+ try:
214
+ result = {"file":value[1].filename,
215
+ "line": value[1].lineno,
216
+ "function": value[1].function,
217
+ "code_context": value[1].code_context[0].strip(),
218
+ "index": value[1].index
219
+ }
220
+ except Exception as error:
221
+ msg = error
222
+ result = msg
223
+ finally:
224
+ return result
225
+
226
+ def __setFileName(self, value):
227
+ msg, result = None, True
228
+ try:
229
+ self.__processo["file"] = value
230
+ except Exception as error:
231
+ msg = error
232
+ result = msg
233
+ finally:
234
+ return result
235
+ #endregion
236
+
237
+ #region Property LOG
238
+ @property
239
+ def LOG_DETAIL(self):
240
+ return self.__list_log_detail
241
+
242
+ @ property
243
+ def LOG_HEADER(self):
244
+ return self.__log_header
245
+ #endregion
246
+
247
+ #region Property´s CALL
248
+ @property
249
+ def CALL_FUNCTION(self):
250
+ return self.__call_origin["function"]
251
+
252
+ @property
253
+ def CALL_LINE(self):
254
+ return self.__call_origin["line"]
255
+
256
+ @property
257
+ def CALL_FILE(self):
258
+ return self.__call_origin["file"]
259
+
260
+ @property
261
+ def CALL_CONTEXT(self):
262
+ return self.__call_origin["code_context"]
263
+
264
+ @property
265
+ def CALL_INDEX(self):
266
+ return self.__call_origin["index"]
267
+ #endregion
268
+
269
+ #region Property´s diversas
270
+ @property
271
+ def PROCESSO(self):
272
+ return self.__processo
273
+
274
+ @property
275
+ def CONN(self):
276
+ return self.__processo["conexao"]
277
+
278
+ @property
279
+ def FILELOG(self):
280
+ return self.PROCESSO["file"]
281
+ # endregion
282
+
283
+ #region DML LOG
284
+ # ----------------------------------
285
+ def setInsertLOG(self):
286
+ msg, result = None, True
287
+ try:
288
+ owner = ""
289
+ stmt = f"""
290
+ Insert into {owner}LOG
291
+ (HASH
292
+ ,NOM_ROTINA
293
+ ,NOM_SUBROTINA
294
+ ,DESCRICAO
295
+ ,FILE
296
+ ,OS_USER
297
+ ,USER_DB
298
+ ,LOCAL_IP
299
+ ,LOCAL_NAME
300
+ ,PROCESSOR
301
+ ,SO_PLATFORM
302
+ ,SO_SYSTEM
303
+ ,SO_VERSION
304
+ ,TIMESTAMP
305
+ ,VERSAO
306
+ )
307
+ VALUES(:hash
308
+ ,:nom_rotina
309
+ ,:nom_subrotina
310
+ ,:descricao
311
+ ,:file
312
+ ,:os_user
313
+ ,:user_db
314
+ ,:local_ip
315
+ ,:local_name
316
+ ,:processor
317
+ ,:so_platform
318
+ ,:so_system
319
+ ,:so_version
320
+ ,:timestamp
321
+ ,:versao
322
+ )
323
+ """
324
+ if self.CONN is not None:
325
+ __head = self.LOG_HEADER
326
+ del(__head["event_content"])
327
+ self.CONN.execute(stmt, __head)
328
+ self.CONN.commit()
329
+ result = "Log HEADER criado!"
330
+ else:
331
+ raise Exception("Não foi fornecido uma conexao com banco de dados!")
332
+ except Exception as error:
333
+ msg = error
334
+ result = msg
335
+ finally:
336
+ return result
337
+
338
+ # ----------------------------------
339
+ def setInsertEVENT(self):
340
+ msg, result = None, True
341
+ try:
342
+ owner = ""
343
+ stmt = f"""
344
+ Insert into {owner}LOG_EVENT
345
+ (HASH
346
+ ,HASH_PARENT
347
+ ,TIMESTAMP
348
+ ,LEVEL_CODE
349
+ ,LEVEL_NAME
350
+ ,FUNCTION_NAME
351
+ ,FUNC_LINE
352
+ ,FUNC_INDEX
353
+ ,CODE_COTEXT
354
+ ,CODE_FILE
355
+ ,EVENT_CONTENT
356
+ )
357
+ VALUES(:hash
358
+ ,:hash_parent
359
+ ,:timestamp
360
+ ,:level_code
361
+ ,:level_name
362
+ ,:function_name
363
+ ,:func_line
364
+ ,:func_index
365
+ ,:code_context
366
+ ,:code_file
367
+ ,:event_content
368
+ )
369
+ """
370
+ if self.CONN is not None:
371
+ __detail = self.LOG_DETAIL
372
+ self.CONN.executemany(stmt, __detail)
373
+ self.CONN.commit()
374
+ result = "Log DETAIL criado!"
375
+ else:
376
+ raise Exception("Não foi fornecido uma conexao com banco de dados!")
377
+ except Exception as error:
378
+ msg = error
379
+ result = msg
380
+ finally:
381
+ return result
382
+
383
+ #endregion
384
+
385
+ #region DDL LOG
386
+ # ----------------------------------
387
+ def DDL_LOG(self, base: str = "SQLite"):
388
+ msg, result = None, True
389
+ try:
390
+ if base == "SQLite":
391
+ log = f"""
392
+ CREATE TABLE IF NOT EXISTS LOG_TESTE (
393
+ HASH TEXT(32) NOT NULL,
394
+ NOM_ROTINA TEXT(50) NOT NULL,
395
+ NOM_SUBROTINA TEXT(128),
396
+ DESCRICAO TEXT(256),
397
+ FILE TEXT(256),
398
+ OS_USER TEXT(128),
399
+ USER_DB TEXT(128),
400
+ LOCAL_IP TEXT(32),
401
+ LOCAL_NAME TEXT(64),
402
+ PROCESSOR TEXT(32),
403
+ SO_PLATFORM TEXT(32),
404
+ SO_SYSTEM TEXT(32),
405
+ SO_VERSION TEXT(32),
406
+ "TIMESTAMP" TIMESTAMP DEFAULT (datetime('now')) NOT NULL,
407
+ VERSAO TEXT(32),
408
+ CONSTRAINT LOG_PK PRIMARY KEY (HASH)
409
+ );
410
+ """
411
+ event = f"""
412
+ CREATE TABLE IF NOT EXISTS LOG_EVENT_TESTE (
413
+ HASH TEXT(32) NOT NULL,
414
+ HASH_PARENT TEXT(32) NOT NULL,
415
+ "TIMESTAMP" TIMESTAMP DEFAULT (datetime('now')) NOT NULL,
416
+ LEVEL_CODE TEXT(16) ,
417
+ LEVEL_NAME TEXT(16) ,
418
+ FUNCTION_NAME TEXT(128) ,
419
+ FUNC_LINE INT,
420
+ FUNC_INDEX INT,
421
+ CODE_COTEXT TEXT(256),
422
+ CODE_FILE TEXT(256),
423
+ EVENT_CONTENT TEXT(512),
424
+ CONSTRAINT LOG_EVENT_PK PRIMARY KEY (HASH)
425
+ );
426
+ """
427
+ elif base == "ORACLE":
428
+ log = f"""CREATE TABLE IF NOT EXISTS LOG_TESTE (
429
+ HASH VARCHAR2(32) NOT NULL,
430
+ NOM_ROTINA VARCHAR2(50) NOT NULL,
431
+ NOM_SUBROTINA VARCHAR2(128),
432
+ DESCRICAO VARCHAR2(256),
433
+ FILE VARCHAR2(256),
434
+ OS_USER VARCHAR2(128),
435
+ USER_DB VARCHAR2(128),
436
+ LOCAL_IP VARCHAR2(32),
437
+ LOCAL_NAME VARCHAR2(64),
438
+ PROCESSOR VARCHAR2(32),
439
+ SO_PLATFORM VARCHAR2(32),
440
+ SO_SYSTEM VARCHAR2(32),
441
+ SO_VERSION VARCHAR2(32),
442
+ "TIMESTAMP" TIMESTAMP DEFAULT (datetime('now')) NOT NULL,
443
+ VERSAO VARCHAR2(32),
444
+ CONSTRAINT LOG_PK PRIMARY KEY (HASH)
445
+ );
446
+ """
447
+ event = f"""
448
+ CREATE TABLE IF NOT EXISTS LOG_EVENT_TESTE (
449
+ HASH VARCHAR2(32) NOT NULL,
450
+ HASH_PARENT VARCHAR2(32) NOT NULL,
451
+ "TIMESTAMP" TIMESTAMP DEFAULT (datetime('now')) NOT NULL,
452
+ LEVEL_CODE VARCHAR2(16) ,
453
+ LEVEL_NAME VARCHAR2(16) ,
454
+ FUNCTION_NAME VARCHAR2(128) ,
455
+ FUNC_LINE INT,
456
+ FUNC_INDEX INT,
457
+ CODE_COVARCHAR2 VARCHAR2(256),
458
+ CODE_FILE VARCHAR2(256),
459
+ EVENT_CONTENT VARCHAR2(512),
460
+ CONSTRAINT LOG_EVENT_PK PRIMARY KEY (HASH)
461
+ );
462
+ """
463
+
464
+ except Exception as error:
465
+ msg = error
466
+ result = msg
467
+ finally:
468
+ return result
469
+ #endregion
470
+
DE_Lib/Log/__init__.py ADDED
File without changes
@@ -0,0 +1,65 @@
1
+ from Crypto.Random import get_random_bytes
2
+ from Crypto.Cipher import AES, PKCS1_OAEP
3
+ from Crypto.Util.Padding import pad, unpad
4
+ import base64
5
+
6
+ class AES_Cipher:
7
+ """
8
+ Esta classe faz criptografia de textos longos
9
+ """
10
+ def __init__(self):
11
+ ...
12
+
13
+ @staticmethod
14
+ def encrypt(plaintext: str, rsa_public_key):
15
+ msg, result = None, True
16
+ try:
17
+ # Gerar uma chave AES aleatória (16 bytes)
18
+ aes_key = get_random_bytes(16)
19
+
20
+ # Criar cifra AES em modo CBC
21
+ cipher_aes = AES.new(aes_key, AES.MODE_CBC)
22
+ iv = cipher_aes.iv # Vetor de Inicialização
23
+
24
+ # Adicionar padding ao texto para que seja múltiplo de 16
25
+ ciphertext = cipher_aes.encrypt(pad(plaintext.encode(), AES.block_size))
26
+
27
+ # Criptografar a chave AES com RSA
28
+ cipher_rsa = PKCS1_OAEP.new(rsa_public_key)
29
+ encrypted_aes_key = cipher_rsa.encrypt(aes_key)
30
+ result = base64.b64encode(encrypted_aes_key + iv + ciphertext).decode()
31
+ except Exception as error:
32
+ msg = error
33
+ result = msg
34
+ finally:
35
+ return result
36
+
37
+
38
+ @staticmethod
39
+ def decrypt(encrypted_data: str, rsa_private_key):
40
+ msg, result = None, True
41
+ try:
42
+ # Converter de base64 para bytes
43
+ encrypted_data = base64.b64decode(encrypted_data)
44
+
45
+ # Extrair partes (chave AES criptografada + IV + texto criptografado)
46
+ key_size = rsa_private_key.size_in_bytes()
47
+ encrypted_aes_key = encrypted_data[:key_size]
48
+ iv = encrypted_data[key_size:key_size + 16]
49
+ ciphertext = encrypted_data[key_size + 16:]
50
+
51
+ # Descriptografar a chave AES com RSA
52
+ cipher_rsa = PKCS1_OAEP.new(rsa_private_key)
53
+ aes_key = cipher_rsa.decrypt(encrypted_aes_key)
54
+
55
+ # Descriptografar o texto com AES
56
+ cipher_aes = AES.new(aes_key, AES.MODE_CBC, iv)
57
+ plaintext = unpad(cipher_aes.decrypt(ciphertext), AES.block_size)
58
+
59
+ result = plaintext.decode()
60
+
61
+ except Exception as error:
62
+ msg = error
63
+ result = msg
64
+ finally:
65
+ return result
@@ -0,0 +1,37 @@
1
+ from argon2 import PasswordHasher
2
+
3
+ class ARGON2:
4
+ # ----------------------------------
5
+ def __init__(self):
6
+ msg, result = None, True
7
+ try:
8
+ self.__ph = PasswordHasher()
9
+ except Exception as error:
10
+ msg = error
11
+ result = msg
12
+
13
+ # ----------------------------------
14
+ def hash(self, value):
15
+ msg, result = None, True
16
+ try:
17
+ result = self.HASH.hash(value)
18
+ except Exception as error:
19
+ msg = error
20
+ result = msg
21
+ finally:
22
+ return result
23
+
24
+ # ----------------------------------
25
+ def validHash(self, value, key):
26
+ msg, result = None, True
27
+ try:
28
+ result = self.HASH.verify(key, value)
29
+ except Exception as error:
30
+ msg = error
31
+ result = msg
32
+ finally:
33
+ return result
34
+
35
+ @property
36
+ def HASH(self):
37
+ return self.__ph
@@ -0,0 +1,48 @@
1
+ import base64
2
+
3
+ class B64_Cipher:
4
+ def __init__(self):
5
+ ...
6
+
7
+ @staticmethod
8
+ def base64_encrypt(word: str, encode_pattern: str = "utf-8"):
9
+ encoded = (base64.b64encode(word.encode(encode_pattern)))
10
+ encoded_ascii = encoded.decode(encode_pattern)
11
+ return encoded_ascii
12
+
13
+ @staticmethod
14
+ def base64_decrypt(word: str, encode_pattern: str = "utf-8"):
15
+ try:
16
+ word = word.encode(encode_pattern)
17
+ decoded = base64.b64decode(word).decode(encode_pattern)
18
+ # decoded_ascii = decoded.decode()
19
+ except Exception as error:
20
+ decoded = error
21
+ finally:
22
+ return decoded
23
+
24
+ @staticmethod
25
+ def token_get() -> str:
26
+ # key = Fernet.generate_key()
27
+ # cipher_suite = Fernet(key)
28
+ cipher_suite = True
29
+ # return key.decode("ascii")
30
+ return cipher_suite
31
+
32
+ @staticmethod
33
+ def CRYPTOGRAPHY(word: str, token: str = None, action: str = "E"):
34
+ msg, result = None, None
35
+ try:
36
+ if action == "E":
37
+ if isinstance(word, str):
38
+ word = word.encode()
39
+ result = token.encrypt(word).decode()
40
+ else:
41
+ if isinstance(word, str):
42
+ word = word.encode()
43
+ result = token.decrypt(word).decode()
44
+ except Exception as error:
45
+ msg = error.args[0]
46
+ result = msg
47
+ finally:
48
+ return result