blob: 04fd036a4229305fc9ab5b66459c13b2f9410cd5 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Tango.Core.Cryptography
{
public class MachineLevelCryptographer : ICryptographer
{
public string Encrypt(string text)
{
return Encrypt(text, "Twine1357");
}
public string Encrypt(string text, string key)
{
return Convert.ToBase64String(
ProtectedData.Protect(
Encoding.UTF8.GetBytes(text)
, key != null ? Encoding.UTF8.GetBytes(key) : null
, DataProtectionScope.LocalMachine));
}
public string Decrypt(string text)
{
return Decrypt(text, "Twine1357");
}
public string Decrypt(string text, string key)
{
return Encoding.UTF8.GetString(
ProtectedData.Unprotect(
Convert.FromBase64String(text)
, key != null ? Encoding.UTF8.GetBytes(key) : null
, DataProtectionScope.LocalMachine));
}
}
}
|