Solved

Ecrypt Password C#

Posted on 2010-08-15
4
749 Views
Last Modified: 2012-05-10
Hi Experts, i need a simple solution .
i have a program i wrote in C# the requiers gmail user name and password inorder to send email notification to the user.
i currntly store these details is the registry , i would like to encrypt the password.
so if someone explores the registry using regedit he won't be able to extract the password.

this is in C# (Visual Studio 2010)
Thanks
0
Comment
Question by:logicthought
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
msimn earned 500 total points
ID: 33439722
Try visiting this website:
http://www.dijksterhuis.org/encrypting-decrypting-string/

You will still need to create a passphrase which you might hardcode it in your program.
0
 
LVL 3

Expert Comment

by:msimn
ID: 33439732
Or, you might try a salted base-64 encode as the following example.

Note that you might want to change the string manipulation part to anything you could think of.
public static string EncodeTo64(string toEncode)

    {

      byte[] toEncodeAsBytes

            = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);

      string returnValue

            = System.Convert.ToBase64String(toEncodeAsBytes);

      return (new Random()).Next(0, 9) + returnValue + (new Random()).Next(0, 9);

    }



public static string DecodeFrom64(string encodedData)

    {

      encodedData = encodedData.substring(1, encodedData.Length - 2);

      byte[] encodedDataAsBytes

          = System.Convert.FromBase64String(encodedData);

      string returnValue =

         System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);

      return returnValue;

    }



public static void main(String[] args)

    {

      string encodedPassword = EncodeTo64("MyPassword");

      Console.WriteLine("Encoded password = " + encodedPassword);



      string decodedPassword = DecodeFrom64(encodedPassword);

      Console.WriteLine("Decoded password = " + decodedPassword);

    }

Open in new window

0
 
LVL 12

Expert Comment

by:starlite551
ID: 33444157
I hope this works for u.. I am attaching a .cs file with my comment plz do check it..
EncryptDecrypt.cs
0
 
LVL 12

Expert Comment

by:starlite551
ID: 33444159
Compile this above file using the command line compiler which comes with visual studio.. as follows :
csc /t:winexe EncryptDecrypt.cs  
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now