Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to generate and give serial number and validate it in windows application during deployment Visual Studio 2005 :(
Posted
Updated 21-Sep-10 0:09am
v4

Here is a simple Encrypt and Decrypt. Very basic.
What you do is display the HDD or CPU serial code.
Then if encrypt it and send it back to your client, he/she then adds the encrypted code in and then your app decrypts the code and matches against the HDD or CPU code and if Matches they user can login.

public class Security
    {
        private const string Key = "31428571428571428571428571428571";

        public static string SimpleEncrypt(string toEncrypt)
        {
            int len = toEncrypt.Length;
            const int keyMin = 0;
            int keyMax = Key.Length;
            int count = 0;
            List<char> encryptedCodes = new List<char>();

            for (int i = 0; i < len; i++)
            {
                if (count == keyMax)
                {
                    count = keyMin;
                }
                int asciiDec = ((int)(toEncrypt[i])) + Convert.ToInt32(Key[count]);
                encryptedCodes.Add((char)asciiDec);
            }
            return new string(encryptedCodes.ToArray());
        }
        public static string SimpleDecrypt(string toDecrypt)
        {
            int len = toDecrypt.Length;
            const int keyMin = 0;
            int keyMax = Key.Length;
            int count = 0;
            List<char> encryptedCodes = new List<char>();

            for (int i = 0; i < len; i++)
            {
                if (count == keyMax)
                {
                    count = keyMin;
                }
                int asciiDec = ((int)(toDecrypt[i])) - Convert.ToInt32(Key[count]);
                encryptedCodes.Add((char)asciiDec);
            }
            return new string(encryptedCodes.ToArray());
        }
    }


Please vote if this helps.
 
Share this answer
 
Comments
thalir 21-Sep-10 8:40am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
stylez500 17-Feb-12 19:14pm    
Could you send that project plz
stylez500 17-Feb-12 19:14pm    
I have 1 but mind is more complicated your look really simple
rashi543 23-Feb-12 8:39am    
but how and where to use it
Google "C# serial number in my application".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900