Hash Algoritma
Technology | C# |
---|---|
Editor of the Page | Latif Bahadır ALTUN |
using System;
using System.Text;
namespace Framework.Utilities.Security.Encryption
{
public class StringEncryptionHelper
{
public static string encryptString(string text, byte xorConstant)
{
if (string.IsNullOrEmpty(text))
return string.Empty;
byte[] data = Encoding.UTF8.GetBytes(text);
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(data[i] ^ xorConstant);
}
return Convert.ToBase64String(data);
}
public static string decryptString(string text, byte xorConstant)
{
if (string.IsNullOrEmpty(text))
return string.Empty;
byte[] data;
try
{
data = Convert.FromBase64String(text);
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(data[i] ^ xorConstant);
}
}
catch
{
return string.Empty;
}
return Encoding.UTF8.GetString(data);
}
}
}