Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Car/HarPadRee/EncryptHash/EncriptionEngine.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (46 sloc)
1.91 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Security.Cryptography; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace HarPadRee | |
{ | |
public class EncriptionEngine | |
{ | |
/// <summary> | |
/// encrypts the string | |
/// </summary> | |
/// <param name="input">the string to be encrypted</param> | |
/// <returns>encrypted string</returns> | |
public static string Encrypt(string input) | |
{ | |
byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input); | |
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); | |
tripleDES.Key = UTF8Encoding.UTF8.GetBytes("halw-3hq8-sq2219"); | |
tripleDES.Mode = CipherMode.ECB; | |
tripleDES.Padding = PaddingMode.PKCS7; | |
ICryptoTransform cTransform = tripleDES.CreateEncryptor(); | |
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); | |
tripleDES.Clear(); | |
return Convert.ToBase64String(resultArray, 0, resultArray.Length); | |
} | |
/// <summary> | |
/// decrypted the string | |
/// </summary> | |
/// <param name="input">the string to be decrypted</param> | |
/// <returns>decrypted string</returns> | |
public static string Decrypt(string input) | |
{ | |
byte[] inputArray = Convert.FromBase64String(input); | |
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); | |
tripleDES.Key = UTF8Encoding.UTF8.GetBytes("halw-3hq8-sq2219"); | |
tripleDES.Mode = CipherMode.ECB; | |
tripleDES.Padding = PaddingMode.PKCS7; | |
ICryptoTransform cTransform = tripleDES.CreateDecryptor(); | |
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); | |
tripleDES.Clear(); | |
return UTF8Encoding.UTF8.GetString(resultArray); | |
} | |
} | |
} |