-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maskunmaskdata.cs
38 lines (31 loc) · 1.16 KB
/
Maskunmaskdata.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Text;
public class DataMasking
{
// Define a key for XOR encryption
private const string EncryptionKey = "SecretKey";
// Function to mask data using XOR encryption
public static string MaskData(string data)
{
byte[] dataBytes = Encoding.UTF8.GetBytes(data);
byte[] keyBytes = Encoding.UTF8.GetBytes(EncryptionKey);
byte[] maskedBytes = new byte[dataBytes.Length];
for (int i = 0; i < dataBytes.Length; i++)
{
maskedBytes[i] = (byte)(dataBytes[i] ^ keyBytes[i % keyBytes.Length]);
}
return Convert.ToBase64String(maskedBytes);
}
// Function to unmask data using XOR encryption
public static string UnmaskData(string maskedData)
{
byte[] maskedBytes = Convert.FromBase64String(maskedData);
byte[] keyBytes = Encoding.UTF8.GetBytes(EncryptionKey);
byte[] unmaskedBytes = new byte[maskedBytes.Length];
for (int i = 0; i < maskedBytes.Length; i++)
{
unmaskedBytes[i] = (byte)(maskedBytes[i] ^ keyBytes[i % keyBytes.Length]);
}
return Encoding.UTF8.GetString(unmaskedBytes);
}
}