Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Azure
GitHub Repository: Azure/Azure-Sentinel-Notebooks
Path: blob/master/src/SentinelUtilities/SentinelUtils/obfuscation_utility.py
3255 views
1
# -------------------------------------------------------------------------
2
# Copyright (c) Microsoft Corporation. All rights reserved.
3
# Licensed under the MIT License. See License.txt in the project root for
4
# license information.
5
# --------------------------------------------------------------------------
6
"""
7
obfuscation_utility module:
8
This module provides obfuscation functionalities
9
"""
10
11
from cryptography.fernet import Fernet
12
13
14
class ObfuscationUtility():
15
""" This class provides utility methods for obfuscation """
16
def __init__(self, seed):
17
self.seed = seed
18
19
@staticmethod
20
def generate_seed():
21
""" Generate seed """
22
23
return Fernet.generate_key()
24
25
def obfuscate_text(self, text):
26
""" Obfuscate input text using key """
27
28
fernet = Fernet(self.seed)
29
en_text = fernet.encrypt(text)
30
return en_text
31
32
def deobfuscate_text(self, en_text):
33
""" De-obfuscate input text using key """
34
35
fernet = Fernet(self.seed)
36
re_text = fernet.decrypt(en_text)
37
return re_text.decode('utf-8')
38
39