-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptoEngine.cs
More file actions
54 lines (50 loc) · 1.83 KB
/
CryptoEngine.cs
File metadata and controls
54 lines (50 loc) · 1.83 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
namespace EncryptDecrypt
{
public static class CryptoEngine
{
public static string Key
{
get
{
string _key= "adfvblmewyign#$%";
return _key;
}
}
public static string Encrypt(this string input)
{
byte[] inputArray = Encoding.UTF8.GetBytes(input);
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider
{
Key = Encoding.UTF8.GetBytes(Key),
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
ICryptoTransform cTransform = tripleDes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
tripleDes.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
public static string Decrypt(this string input)
{
byte[] inputArray = Convert.FromBase64String(input);
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider
{
Key = Encoding.UTF8.GetBytes(Key),
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
ICryptoTransform cTransform = tripleDes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
tripleDes.Clear();
return Encoding.UTF8.GetString(resultArray);
}
}
}