3 Replies - 4945 Views - Last Post: 17 January 2008 - 01:15 PM Rate Topic: -----

#1 danmor498  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-January 08

encryp decrypt

Post icon  Posted 17 January 2008 - 10:05 AM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: encryp decrypt

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4354
  • View blog
  • Posts: 12,160
  • Joined: 18-April 07

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! :)
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5848
  • View blog
  • Posts: 12,707
  • Joined: 16-October 07

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.

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

Was This Post Helpful? 0
  • +
  • -

#4 danmor498  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-January 08

Re: encryp decrypt

Posted 17 January 2008 - 01:15 PM

View PostMartyr2, 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! :)

:D Sorry for that i will try not to do it again have a nyce day

View Postbaavgai, 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.

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1