Register for your free account! | Forgot your password?

You last visited: Today at 14:52

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Init BlowFish!!!

Discussion on Init BlowFish!!! within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
Init BlowFish!!!

PHP Code:
//  CipherMode may be "ecb", "cbc", or "cfb"
            
cipher.CipherMode "cfb";
//  KeyLength (in bits) may be a number between 32 and 448.
            
cipher.KeyLength 128;
//  The padding scheme determines the contents of the bytes
//  that are added to pad the result to a multiple of the
//  encryption algorithm's block size.  Blowfish has a block
//  size of 8 bytes, so encrypted output is always
//  a multiple of 8.
            
cipher.PaddingScheme 64;
//  EncodingMode specifies the encoding of the output for
//  encryption, and the input for decryption.
//  It may be "hex", "url", "base64", or "quoted-printable".
            
cipher.EncodingMode "hex";
//  An initialization vector is required if using CBC or CFB modes.
//  ECB mode does not use an IV.
//  The length of the IV is equal to the algorithm's block size.
//  It is NOT equal to the length of the key.
            
cipher.SetEncodedIV(Encoding.ASCII.GetString(new byte[8]), "hex");
//  The secret key must equal the size of the key.  For
//  256-bit encryption, the binary secret key is 32 bytes.
//  For 128-bit encryption, the binary secret key is 16 bytes.
            
cipher.SetEncodedKey("DR654dt34trg4UI6""hex"); 
the lib can be found here
so what's wrong here !? it's not working? did i init something wrong?
Mr_PoP is offline  
Old 06/26/2011, 20:18   #2
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,223
Received Thanks: 867
// KeyLength (in bits) may be a number between 32 and 448.
cipher.KeyLength = 16;

16? It my be >= 32 and <= 448
_DreadNought_ is offline  
Old 06/26/2011, 20:27   #3
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
Quote:
Originally Posted by _DreadNought_ View Post
// KeyLength (in bits) may be a number between 32 and 448.
cipher.KeyLength = 16;

16? It my be >= 32 and <= 448
it's not really the prob coz i changed it in my codes



you can find the lib there , do you know better lib to use?
Mr_PoP is offline  
Old 06/26/2011, 20:50   #4


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
The one every other source here uses would be a good place to start...
Korvacs is offline  
Old 06/26/2011, 21:14   #5
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
Quote:
Originally Posted by Korvacs View Post
The one every other source here uses would be a good place to start...
well i was working with BouncyCastel but it seems like it's not working good, becuase it makes me dc from the client
Mr_PoP is offline  
Old 06/26/2011, 21:22   #6


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Quote:
Originally Posted by Mr_PoP View Post
well i was working with BouncyCastel but it seems like it's not working good, becuase it makes me dc from the client
The majority of Sources here use ManagedOpenSSL or just straight up OpenSSL using invoking and a C++ Wrapper.
Korvacs is offline  
Old 06/26/2011, 21:30   #7
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
Quote:
Originally Posted by Korvacs View Post
The majority of Sources here use ManagedOpenSSL or just straight up OpenSSL using invoking and a C++ Wrapper.
does ManagedOpenSSL has BlowfishCfb?
Mr_PoP is offline  
Old 06/26/2011, 21:33   #8


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Quote:
Originally Posted by Mr_PoP View Post
does ManagedOpenSSL has BlowfishCfb?
Would be difficult for people to use it for Conquer if it didnt have the correct crypto methods and types...
Korvacs is offline  
Old 06/26/2011, 21:44   #9
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
Quote:
Originally Posted by Korvacs View Post
Would be difficult for people to use it for Conquer if it didnt have the correct crypto methods and types...
Code:
public class GameCryptography
    {
        Blowfish _blowfish;
        public GameCryptography(byte[] key)
        {
            _blowfish = new Blowfish(BlowfishAlgorithm.CFB64);
            _blowfish.SetKey(key);
        }

        public void Decrypt(byte[] packet)
        {
            byte[] buffer = _blowfish.Decrypt(packet);
            System.Buffer.BlockCopy(buffer, 0, packet, 0, buffer.Length);
        }

        public void Encrypt(byte[] packet)
        {
            byte[] buffer = _blowfish.Encrypt(packet);
            System.Buffer.BlockCopy(buffer, 0, packet, 0, buffer.Length);
        }

        public Blowfish Blowfish
        {
            get { return _blowfish; }
        }
        public void SetKey(byte[] k)
        {
            _blowfish.SetKey(k);
        }
        public void SetIvs(byte[] i1, byte[] i2)
        {
            _blowfish.EncryptIV = i1;
            _blowfish.DecryptIV = i2;
        }
    }

    public enum BlowfishAlgorithm
    {
        ECB,
        CBC,
        CFB64,
        OFB64,
    };

    public class Blowfish : IDisposable
    {
        [DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern static void BF_set_key(IntPtr _key, int len, byte[] data);

       [DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern static void BF_ecb_encrypt(byte[] in_, byte[] out_, IntPtr schedule, int enc);

       [DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern static void BF_cbc_encrypt(byte[] in_, byte[] out_, int length, IntPtr schedule, byte[] ivec, int enc);

       [DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern static void BF_cfb64_encrypt(byte[] in_, byte[] out_, int length, IntPtr schedule, byte[] ivec, ref int num, int enc);

        [DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern static void BF_ofb64_encrypt(byte[] in_, byte[] out_, int length, IntPtr schedule, byte[] ivec, out int num);

        [StructLayout(LayoutKind.Sequential)]
        struct bf_key_st
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)]
            public UInt32[] P;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
            public UInt32[] S;
        }

        private BlowfishAlgorithm _algorithm;
        private IntPtr _key;
        private byte[] _encryptIv;
        private byte[] _decryptIv;
        private int _encryptNum;
        private int _decryptNum;

        public Blowfish(BlowfishAlgorithm algorithm)
        {
            _algorithm = algorithm;
            _encryptIv = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
            _decryptIv = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
            bf_key_st key = new bf_key_st();
            key.P = new UInt32[16 + 2];
            key.S = new UInt32[4 * 256];
            _key = Marshal.AllocHGlobal(key.P.Length * sizeof(UInt32) + key.S.Length * sizeof(UInt32));
            Marshal.StructureToPtr(key, _key, false);
            _encryptNum = 0;
            _decryptNum = 0;
        }

        public void Dispose()
        {
            Marshal.FreeHGlobal(_key);
        }

        public void SetKey(byte[] data)
        {
            _encryptNum = 0;
            _decryptNum = 0;
            BF_set_key(_key, data.Length, data);
        }

        public byte[] Encrypt(byte[] buffer)
        {
            byte[] ret = new byte[buffer.Length];
            switch (_algorithm)
            {
                case BlowfishAlgorithm.ECB:
                    BF_ecb_encrypt(buffer, ret, _key, 1);
                    break;
                case BlowfishAlgorithm.CBC:
                    BF_cbc_encrypt(buffer, ret, buffer.Length, _key, _encryptIv, 1);
                    break;
                case BlowfishAlgorithm.CFB64:
                    BF_cfb64_encrypt(buffer, ret, buffer.Length, _key, _encryptIv, ref _encryptNum, 1);
                    break;
                case BlowfishAlgorithm.OFB64:
                    BF_ofb64_encrypt(buffer, ret, buffer.Length, _key, _encryptIv, out _encryptNum);
                    break;
            }
            return ret;
        }

        public byte[] Decrypt(byte[] buffer)
        {
            byte[] ret = new byte[buffer.Length];
            switch (_algorithm)
            {
                case BlowfishAlgorithm.ECB:
                    BF_ecb_encrypt(buffer, ret, _key, 0);
                    break;
                case BlowfishAlgorithm.CBC:
                    BF_cbc_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, 0);
                    break;
                case BlowfishAlgorithm.CFB64:
                    BF_cfb64_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, ref _decryptNum, 0);
                    break;
                case BlowfishAlgorithm.OFB64:
                    BF_ofb64_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, out _decryptNum);
                    break;
            }
            return ret;
        }

        public byte[] EncryptIV
        {
            get { return _encryptIv; }
            set { System.Buffer.BlockCopy(value, 0, _encryptIv, 0, 8); }
        }

        public byte[] DecryptIV
        {
            get { return _decryptIv; }
            set { System.Buffer.BlockCopy(value, 0, _decryptIv, 0, 8); }
        }
    }
so this one will work just perfecet?
Mr_PoP is offline  
Reply


Similar Threads Similar Threads
EasyMT2 Init failed?!
06/02/2011 - Metin2 - 11 Replies
hallo ich ollte grade eben easymetin2 laufen lassen und wenn ich neues spiel starten drücke kommt ne fehlermeldung "init failed (1)" wie kann ich das problem beheben? danke
BlowFish
02/14/2011 - CO2 Private Server - 15 Replies
is there anycode for Blowfish here in C++ works with the later clients?! like the one in ExodusBinaries?
[help]blowfish
10/15/2009 - Lineage 2 - 0 Replies
hello i haven't idea how to find blowfish in server any idea?



All times are GMT +2. The time now is 14:52.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.