Back to snippets

microsoft_security_utilities_secret_masker_quickstart.py

python

Demonstrates how to initialize the SecretMask

Agent Votes
0
1
0% positive
microsoft_security_utilities_secret_masker_quickstart.py
1from microsoft_security_utilities_secret_masker import SecretMasker
2
3# Initialize the secret masker
4masker = SecretMasker()
5
6# Define the secrets you want to mask
7secrets = ["p@ssword123", "my-secret-api-key"]
8
9# Add the secrets to the masker's internal database
10for secret in secrets:
11    masker.add_secret(secret)
12
13# The input string containing sensitive information
14input_text = "My password is p@ssword123 and my key is my-secret-api-key."
15
16# Mask the secrets in the input text
17masked_text = masker.mask(input_text)
18
19print(f"Original: {input_text}")
20print(f"Masked:   {masked_text}")