Enctypting stuff

Enctypting stuff

Postby joppiesaus » 13 Jul 2013, 17:39

Hi, I am working on a class to encrypt my save files for a console RPG.
Right now it works simple: Characters are just getting replaced by other characters.
Spoiler:



Spoiler:


Is there any way to make it harder to decrypt?(Not that a character is just replaced by another and that is always the same, but more random).
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Enctypting stuff

Postby ismellike » 13 Jul 2013, 17:55

This is something similar to what I used for encrypting my save file.

http://support.microsoft.com/kb/307010
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Enctypting stuff

Postby joppiesaus » 13 Jul 2013, 18:44

Thank you! I think I would use this.
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Enctypting stuff

Postby joppiesaus » 15 Jul 2013, 08:05

I didn't use your encryption stuff, but instead I coded myself one, I need only to randomize it more(the hard part)
It works great. No errors, but you can change the first part in the TXT file if you know the codes, but later not(see the random outputint)
I want to improve that.

Spoiler:
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Enctypting stuff

Postby Conor » 15 Jul 2013, 13:49

Looks nice. Replacing characters would be easily decrypted by somebody if they really wanted to get to the information. But there probably aren't many people who are going to spend time trying to figure your files out so don't worry ;)

I made this class a while ago, I basically used all the methods from the admin password system in MCForge. I'll post it here in case you want to use it.

Its simple usage, Encryption.Encrypt(string) and Encryption.Decrypt(string) <ok>

Code: Select all
public class Encryption
    {
        // Set your own codes for the encryption, don't tell anybody.
        private static string EncryptionCode = "CHANGEME";
        private static byte[] _salt = Encoding.ASCII.GetBytes("CHANGEME");

        public static string Encrypt(string toEncrypt)
        {
            try
            {
                string outStr = null;
                RijndaelManaged aesAlg = null;

                try
                {
                    Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(EncryptionCode, _salt);

                    aesAlg = new RijndaelManaged();
                    aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);
                    aesAlg.IV = key.GetBytes(aesAlg.BlockSize / 8);

                    ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

                    using (MemoryStream msEncrypt = new MemoryStream())
                    {
                        using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                        {
                            using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                            {
                                swEncrypt.Write(toEncrypt);
                            }
                        }
                        outStr = Convert.ToBase64String(msEncrypt.ToArray());
                    }
                }
                finally
                {
                    if (aesAlg != null)
                        aesAlg.Clear();
                }
                return outStr;
            }
            catch { return "Error"; }
        }

        public static string Decrypt(string toDecrypt)
        {
            try
            {
                RijndaelManaged aesAlg = null;
                string DecryptedString = null;

                try
                {
                    Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(EncryptionCode, _salt);

                    aesAlg = new RijndaelManaged();
                    aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);
                    aesAlg.IV = key.GetBytes(aesAlg.BlockSize / 8);

                    ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

                    byte[] bytes = Convert.FromBase64String(toDecrypt);
                    using (MemoryStream msDecrypt = new MemoryStream(bytes))
                    {
                        using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                        {
                            using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                                DecryptedString = srDecrypt.ReadToEnd();
                        }
                    }
                }
                finally
                {
                    if (aesAlg != null)
                        aesAlg.Clear();
                }
                return DecryptedString;
            }
            catch { return "Error"; }
        }
    }
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Enctypting stuff

Postby joppiesaus » 15 Jul 2013, 14:11

Thanks Conor for your class,
My system isn't fully charreplacement. At the end of the encrypted string is something else, but I want to make a formula that changes everything.
But if I multiply it and then devide it, it wont work. :(
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Enctypting stuff

Postby Conor » 15 Jul 2013, 15:13

joppiesaus wrote:Thanks Conor for your class,
My system isn't fully charreplacement. At the end of the encrypted string is something else, but I want to make a formula that changes everything.
But if I multiply it and then devide it, it wont work. :(


Why won't it work? I haven't looked into it too much but I noticed you used the Random class - maybe this has something to do with why you can't return to the same value, as you don't know what the random number was?
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron