نوشته شده توسط
leontry89
دوستان من یک کلاسی به صورت اکستنشن متد دارم:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
namespace ChapikWebSite.Models
{
public static class Extension
{
public static string Encrypt(this string str)
{
byte[] encData_byte = new byte[str.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(str);
return Convert.ToBase64String(encData_byte);
}
}
}
و در کنترلر هم به این صورت عمل کردم:
Reg.Password.Encrypt();
blReg.Add(Reg);
اما هش نمیشه
از این دو استفاده کنید دوست عزیز :
public static string Encrypt(this string str)
{
byte[] encData_byte = new byte[str.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(str);
return Convert.ToBase64String(encData_byte);
}
public static string Decrypt(this string str)
{
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(str);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
return new string(decoded_char);
}
وقتی هم کد میکنید باید بریزید تو مقدار قبلیش