PDA

View Full Version : رمزی کردن و دی رمزی کردن



ordebehesht
جمعه 26 آبان 1391, 20:49 عصر
آقا ما کامپوننتی چیزی داریم که متنی رو encod و decode کنه
یعنی کلمه عبور و نام کاربری به صورت رمزی وارد شه تو دیتابیس

farghabil
جمعه 26 آبان 1391, 20:58 عصر
باید باشه این چیزا ولی معمولا هرکس خودش مینویسه
hash table رو سرچ کن کداش هست

samadblaj
جمعه 26 آبان 1391, 21:02 عصر
سلام بفرما این کدی که خودم استفاده کردم هیچ خطایی هم نداره...
این hash کردن توسط الگوریتم MD5 الکوریتم رمز نگاری غیر بازگشتی بهترین روش برای ذخیره رمز هستش...


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security .Cryptography ;

namespace coding
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{

string source = "samad";
string hash = getMd5Hash(source);
textBox1 .Text = hash;

if (verifyMd5Hash(source, hash))
{
MessageBox.Show ("The hashes are the same.");
}
else
{
MessageBox .Show ("The hashes are not same.");
}
}


static string getMd5Hash(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();

// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(in put));

// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();

// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}

// Return the hexadecimal string.
return sBuilder.ToString();
}

// Verify a hash against a string.
static bool verifyMd5Hash(string input, string hash)
{
// Hash the input.
string hashOfInput = getMd5Hash(input);

// Create a StringComparer an compare the hashes.
StringComparer comparer = StringComparer.OrdinalIgnoreCase;

if (0 == comparer.Compare(hashOfInput, hash))
{
return true;
}
else
{
return false;
}
}

private void button2_Click(object sender, EventArgs e)
{
if (textBox2.Text == textBox1.Text)
{
MessageBox.Show("y");
}
else
{
MessageBox.Show("n");
}

}
}
}

modern_amin
دوشنبه 25 دی 1391, 10:37 صبح
برا بازگشتیش یراغ ندارید؟

hamedAdmin
دوشنبه 25 دی 1391, 12:06 عصر
کل توابع درهم ساز اینان:


KeyedHashAlgorithm (http://msdn.microsoft.com/en-us/library/system.security.cryptography.keyedhashalgorithm.as px)
MD5 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5.aspx)
RIPEMD160 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.ripemd160.aspx)
SHA1 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx)
SHA256 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha256.aspx)
SHA384 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha384.aspx)
SHA512 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha512.aspx)

حالا یه نمونه مثال:

byte[] result;
SHA1 sha = new SHA1CryptoServiceProvider();
using(FileStream fs = File.OpenRead(@"file.txt"))
{ result = sha.ComputeHash(fs); }

ordebehesht
دوشنبه 25 دی 1391, 12:39 عصر
مرسی همین رو میخواستم یه مجموعه از این توابع md5 ‌و shal رو میدونستم

modern_amin
سه شنبه 26 دی 1391, 08:40 صبح
کل توابع درهم ساز اینان:


KeyedHashAlgorithm (http://msdn.microsoft.com/en-us/library/system.security.cryptography.keyedhashalgorithm.as px)
MD5 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5.aspx)
RIPEMD160 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.ripemd160.aspx)
SHA1 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx)
SHA256 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha256.aspx)
SHA384 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha384.aspx)
SHA512 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha512.aspx)

حالا یه نمونه مثال:

byte[] result;
SHA1 sha = new SHA1CryptoServiceProvider();
using(FileStream fs = File.OpenRead(@"file.txt"))
{ result = sha.ComputeHash(fs); }


یه توضیح در مورد این کد بدید.........

ordebehesht
سه شنبه 26 دی 1391, 13:10 عصر
این کد یه متغیر از نوع بایت ایجاد کرده و یک نمونه از کلاس sha1 ایجاد کرده و خروجی سازنده کلاس shaiCryptografy رو به اون ارجا میده بعد فایلی رو باز و محتویات اونو رو داخل fs از نوع کلاس file strim میریزه سپس با استفاده از متد campoutehash تبدیل به کد رمزی میکنه

نگین بلد بودی چرا پرسیدی متدهایی که این کارر و میکنن رو نمیدونستم

modern_amin
سه شنبه 26 دی 1391, 15:52 عصر
من سکوت اختیار میکنم....

منظورم کاره کلیش بود.... آیا سورس الگوریتم کد کردن بازگشتی رو دارید؟

ordebehesht
سه شنبه 26 دی 1391, 15:54 عصر
چرا بازگشتی؟؟؟؟؟؟؟؟؟؟

modern_amin
سه شنبه 26 دی 1391, 16:00 عصر
برا اینکه بعد کد کردن دوباره بتونم دیکد کنم

ordebehesht
سه شنبه 26 دی 1391, 16:53 عصر
فرک نکنم این متدها dicode‌بشن

ordebehesht
سه شنبه 26 دی 1391, 17:00 عصر
به این سایت سر بزن شاید بردت خورد

modern_amin
چهارشنبه 27 دی 1391, 08:55 صبح
دنباله یچیزه توپ میگردم...

کدوم سایت سر بزنم؟ لینکشو یادتون رفت.....

ordebehesht
چهارشنبه 27 دی 1391, 11:24 صبح
ببخشین یادم رفته
یکی این
http://stackoverflow.com/questions/5917658/reversing-a-md5-hash-algorithm-in-c-sharp
و یکی این
http://www.codeproject.com/Articles/14150/Encrypt-and-Decrypt-Data-with-C