Solved

C# secure / uncesure string

Posted on 2008-10-16
10
505 Views
Last Modified: 2013-12-17
I need in C# 2008 NET 2.0 simple static class  which secure / unsecure string which will be saved in text file. Will be good to be with some key, mean that with different kay to provide different secure string.

Greeting !
0
Comment
Question by:dvplayltd
  • 6
  • 2
  • 2
10 Comments
 
LVL 1

Expert Comment

by:MarkMyburgh
ID: 22730225
HI
query: what do yo mean secure string?  do you have a string encripyted?
you could do something like

var Dic = new Dictionary<string, string>)()

dictionary.Add("Secure", "some string");
dictionary.Add("Unsecure", "some string");
0
 

Author Comment

by:dvplayltd
ID: 22730333
Hi !

 I need class that do function crypt/ decrypt string which will be saved in text file.
0
 
LVL 1

Expert Comment

by:MarkMyburgh
ID: 22730973
you could try implementing something like this
class test

{

    enum StringType

	{

        Encrypt,

        Decrypt	         

	}
 

    private static string MyString { get; set; }
 

    static string GetString(StringType type)

    {
 

        switch (type)

       {

            case StringType.Decrypt: MyString = DoDecrypt(); break;

            case StringType.Encrypt: MyString = DoEncrypt(); break;

        }

        return MyString;

    }

  

}

Open in new window

0
 
LVL 1

Expert Comment

by:MarkMyburgh
ID: 22731074
or if you want to store mutliple strings
 

class test

{

    enum StringType

	{

        Encrypt,

        Decrypt	         

	}
 

    static private Dictionary<string, StringStruc> MyString { get; set; }

    

    static string GetString(string key, StringType type)

    {
 

        switch (type)

       {

            case StringType.Decrypt: 

                {

                    if (MyString[key].Encrypted)

                    {

                        MyString[key].MyString = DoDecrypt();

                    }                    

                }

            case StringType.Encrypt:

                {

                    if (!MyString[key].Encrypted)

                    {

                        MyString[key].MyString = DoEncrypt();

                    }

                }

        }

        return MyString;

    }

  

}
 

struct StringStruc

{

    public string MyString { get; set; }

    public bool Encrypted { get; set; }

}

Open in new window

0
 
LVL 1

Expert Comment

by:MarkMyburgh
ID: 22731124
sorry replace
         return MyString;

with

return MyString[key].MyString;
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Expert Comment

by:MarkMyburgh
ID: 22731336
its been a long day!
forgot to set the flag to true or false if the string has been encrtyped or not

class test

{

    enum StringType

    {

        Encrypt,

        Decrypt

    }
 

    static private Dictionary<string, StringStruc> MyString { get; set; }
 

    static string GetString(string key, StringType type)

    {
 

        switch (type)

        {

            case StringType.Decrypt:

                {

                    if (MyString[key].Encrypted)

                    {

                        MyString[key].MyString = DoDecrypt();

                        MyString[key].Encrypted = false;

                    }

                }

            case StringType.Encrypt:

                {

                    if (!MyString[key].Encrypted)

                    {

                        MyString[key].MyString = DoEncrypt();

                        MyString[key].Encrypted = true;

                    }

                }

        }

        return MyString[key].MyString; 

    }
 

}
 

struct StringStruc

{

    public string MyString { get; set; }

    public bool Encrypted { get; set; }

}

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22732535
You first need to determine whether you need actual ENCRYPTION or a HASH.

(1) Encryption: The value is encoded with a key and stored somewhere.  Then you can retrieve the encoded value, decode it with the key, and you end up with the original value.  This is a TWO WAY system, otherwise known as a symmetric algorithm.  A credit card number would need encryption since you need the actual value to purchase something.  If the "key" is compromised then the data is compromised.

(2) Hashing: The value is "hashed" and converted it to a fixed length value using a hashing algorithm.  Different hash algorithms produce different lengths of hashes.  Then you store the hash somewhere.  Now you can determine if a value entered by the user is the same as the original value by comparing the hashes.  You hash the current value and see if that hash matches the original hash.  A hash is a ONE WAY system.  You CANNOT get the original value back from the hash.  Passwords are often stored as Hashes since you can't figure out what the original value was from looking at the hash.  There is no "key" that can be compromised with hashing.

0
 

Author Comment

by:dvplayltd
ID: 22732861
Encryption is good enough. I will test you example soon. I hope that is full - I mean that with copy/paste will work . IN first look - I don't see code for function DoEncrypt() and DoDecrypt() ?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 22733048
0
 
LVL 1

Expert Comment

by:MarkMyburgh
ID: 22733697
Hi dvplay:td
Did not have time at work to implement the encryption stuff.  have a look at the msdn link above.
else i'll try to smack something together tomorrow for you
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Closing all open child forms. 4 38
IO.FileSystemWatcher dies when used in Powershell 1 45
VB.Net How to Exit Sub - Exit Form??? 5 51
ASP.NET 5 Templates 2 65
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

22 Experts available now in Live!

Get 1:1 Help Now