PDA

View Full Version : هش کردن یک رشته



leontry89
یک شنبه 17 مرداد 1395, 10:45 صبح
دوستان من یک کلاسی به صورت اکستنشن متد دارم:


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);

اما هش نمیشه

m_kalantar.cs
سه شنبه 19 مرداد 1395, 11:58 صبح
به این صورت امتحان کنید



Reg.Password=Reg.Password.Encrypt();

keyone72
سه شنبه 19 مرداد 1395, 15:35 عصر
دوستان من یک کلاسی به صورت اکستنشن متد دارم:


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);
}



وقتی هم کد میکنید باید بریزید تو مقدار قبلیش