Jump to content
RealModScene
Sign in to follow this  
The Cowboy

C# Account File Enc/Dec

Recommended Posts

        public byte[] DecryptAccount(byte[] AccountData)        {            byte[] buffer = new byte[404];            byte[] firstbytes = new byte[16];            Array.Copy(AccountData, firstbytes, 16);            Array.Resize(ref buffer, 16);            Array.Copy(firstbytes, buffer, 16);            System.Security.Cryptography.HMACSHA1 h = new System.Security.Cryptography.HMACSHA1(hmackey);            byte[] rckey = h.ComputeHash(buffer);            Array.Resize(ref rckey, 0x10);            byte[] decrypteddata = new byte[388];            Array.Resize(ref buffer, 388);            Array.Copy(AccountData, 0x10, buffer, 0, 388);            RC4(ref buffer, rckey);            Array.Copy(buffer, decrypteddata, 388);            return decrypteddata;        }        public byte[] EncryptAccount(byte[] AccountData)        {            byte[] buffer = new byte[404];            Array.Copy(AccountData, 0, buffer, 0x10, AccountData.Length);            System.Security.Cryptography.HMACSHA1 hs1 = new System.Security.Cryptography.HMACSHA1(hmackey);            byte[] firstbytes = new byte[16];            Array.Copy(hs1.ComputeHash(AccountData), firstbytes, 16);            Array.Copy(firstbytes, 0, buffer, 0, 16);            byte[] rckey = hs1.ComputeHash(firstbytes);            Array.Resize(ref rckey, 0x10);            byte[] buffertwo = new byte[388];            Array.Copy(buffer, 0x10, buffertwo, 0, 388);            RC4(ref buffertwo, rckey);            Array.Copy(buffertwo, 0, buffer, 0x10, buffertwo.Length);            return buffer;        }        public void RC4(ref Byte[] bytes, Byte[] key)        {            Byte[] s = new Byte[256];            Byte[] k = new Byte[256];            Byte temp;            int i, j;            for (i = 0; i < 256; i++)            {                s[i] = (Byte)i;                k[i] = key[i % key.GetLength(0)];            }            j = 0;            for (i = 0; i < 256; i++)            {                j = (j + s[i] + k[i]) % 256;                temp = s[i];                s[i] = s[j];                s[j] = temp;            }            i = j = 0;            for (int x = 0; x < bytes.GetLength(0); x++)            {                i = (i + 1) % 256;                j = (j + s[i]) % 256;                temp = s[i];                s[i] = s[j];                s[j] = temp;                int t = (s[i] + s[j]) % 256;                bytes[x] ^= s[t];            }        }

I wanted to share it to help other people and i'd like to improve my code so i shared it.

Share this post


Link to post
Share on other sites

OMG! Perfect code.Gonna use this for my next app, thanks a lot ! :)

My code for this project is REALLY bad... xD it's nowhere near clean or even optimized...

  • Like 1

Share this post


Link to post
Share on other sites

My code for this project is REALLY bad... xD it's nowhere near clean or even optimized...

Well, since it is the best codding ive ever seen, i can think it is good.

Share this post


Link to post
Share on other sites

Well, since it is the best codding ive ever seen, i can think it is good.

Thanks :) if you want i can clean it up for ya, make it easier to read and optimize it... :)

  • Like 1

Share this post


Link to post
Share on other sites

Thanks :) if you want i can clean it up for ya, make it easier to read and optimize it... :)

if I understand it that way, it would be a lesson for me :)

Share this post


Link to post
Share on other sites

if I understand it that way, it would be a lesson for me :)

http://www.sendspace.com/file/s90pp9 <--- there you go, much cleaner/better code :) i didn't change the RC4 implementation tho, your implementation of that is probably better (less code) but... i cba to verify that changes made to that actually work atm...
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...