not certain that i did it a the writh place but here it is
looking for a way to encrypt and decrypt text from richtextbox in c#
using sha encrypting simple way since i am a beginner in c# and all i founded in this mather is for password i allready have one.
tank's again for giving me this opportunetie
danmor498
ps; excuse my english since i am french Can. i may be having a bit of troubles to write it properly.
encryp decrypt
Page 1 of 13 Replies - 4302 Views - Last Post: 17 January 2008 - 01:15 PM
Replies To: encryp decrypt
#2
Re: encryp decrypt
Posted 17 January 2008 - 10:26 AM
Welcome to Dream.In.Code danmor498! This is the meet and greet forum and not for programming questions. I will happily move it to the C# forum so that the experts there can help you out. Welcome aboard!
#3
Re: encryp decrypt
Posted 17 January 2008 - 11:48 AM
For most password encryption, it's a one way hash. You can't get the password from the hash, but if you have the right password, it will result in the hash you have.
Here's a quick program in C# to show a way to do it.
Hope this helps.
Here's a quick program in C# to show a way to do it.
using System;
using System.Text;
using System.Diagnostics;
using System.Security.Cryptography;
namespace ConsoleApplication1 {
class Program {
HashAlgorithm hasher = new SHA1CryptoServiceProvider();
public byte[] getHashForString(string s) {
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
return hasher.ComputeHash(bytes);
}
public bool IsMatch(byte[] hash1, byte[] hash2) {
if (hash1.Length != hash2.Length) { return false; }
for (int i = 0; i < hash1.Length; i++) {
if (hash1[i] != hash2[i]) { return false; }
}
return true;
}
public bool IsMatch(byte[] passHash, string password) {
return IsMatch(passHash, getHashForString(password));
}
static void Main(string[] args) {
Program pgm = new Program();
string password = "harvey99";
byte[] passwordHash = pgm.getHashForString(password);
Debug.WriteLine("password=" + password);
Debug.WriteLine(pgm.IsMatch(passwordHash, "foo"));
Debug.WriteLine(pgm.IsMatch(passwordHash, "harvey98"));
Debug.WriteLine(pgm.IsMatch(passwordHash, "harvey99"));
}
}
}
Hope this helps.
This post has been edited by baavgai: 17 January 2008 - 11:48 AM
#4
Re: encryp decrypt
Posted 17 January 2008 - 01:15 PM
Martyr2, on 17 Jan, 2008 - 12:26 PM, said:
Welcome to Dream.In.Code danmor498! This is the meet and greet forum and not for programming questions. I will happily move it to the C# forum so that the experts there can help you out. Welcome aboard! 
baavgai, on 17 Jan, 2008 - 01:48 PM, said:
For most password encryption, it's a one way hash. You can't get the password from the hash, but if you have the right password, it will result in the hash you have.
Here's a quick program in C# to show a way to do it.
Hope this helps.
Here's a quick program in C# to show a way to do it.
using System;
using System.Text;
using System.Diagnostics;
using System.Security.Cryptography;
namespace ConsoleApplication1 {
class Program {
HashAlgorithm hasher = new SHA1CryptoServiceProvider();
public byte[] getHashForString(string s) {
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
return hasher.ComputeHash(bytes);
}
public bool IsMatch(byte[] hash1, byte[] hash2) {
if (hash1.Length != hash2.Length) { return false; }
for (int i = 0; i < hash1.Length; i++) {
if (hash1[i] != hash2[i]) { return false; }
}
return true;
}
public bool IsMatch(byte[] passHash, string password) {
return IsMatch(passHash, getHashForString(password));
}
static void Main(string[] args) {
Program pgm = new Program();
string password = "harvey99";
byte[] passwordHash = pgm.getHashForString(password);
Debug.WriteLine("password=" + password);
Debug.WriteLine(pgm.IsMatch(passwordHash, "foo"));
Debug.WriteLine(pgm.IsMatch(passwordHash, "harvey98"));
Debug.WriteLine(pgm.IsMatch(passwordHash, "harvey99"));
}
}
}
Hope this helps.
Thank for the password encrytion code Have a nyce day
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|