-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptionHelper.cs
More file actions
64 lines (63 loc) · 2.73 KB
/
EncryptionHelper.cs
File metadata and controls
64 lines (63 loc) · 2.73 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Threading.Tasks;
namespace EAACP
{
internal static class EncryptionHelper
{
public static string Encrypt(string plainText)
{
byte[] data = System.Text.Encoding.UTF8.GetBytes(plainText);
byte[] result;
using (System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
{
byte[] keys = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes("$6%ItQ9Eteh1zEPJ"));
using (System.Security.Cryptography.TripleDESCryptoServiceProvider tripDes = new System.Security.Cryptography.TripleDESCryptoServiceProvider()
{
Key = keys,
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
})
{
using (System.Security.Cryptography.ICryptoTransform transform = tripDes.CreateEncryptor())
{
result = transform.TransformFinalBlock(data, 0, data.Length);
}
}
}
return Convert.ToBase64String(result);
}
public static string Decrypt(string encryptedText)
{
try
{
byte[] data = Convert.FromBase64String(encryptedText);
byte[] result;
using (System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
{
byte[] keys = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes("$6%ItQ9Eteh1zEPJ"));
using (System.Security.Cryptography.TripleDESCryptoServiceProvider tripDes = new System.Security.Cryptography.TripleDESCryptoServiceProvider()
{
Key = keys,
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
})
{
using (System.Security.Cryptography.ICryptoTransform transform = tripDes.CreateDecryptor())
{
result = transform.TransformFinalBlock(data, 0, data.Length);
}
}
}
return System.Text.Encoding.UTF8.GetString(result);
}
catch(Exception)
{
return encryptedText; // pass back what was passed in
}
}
}
}