Beispiel #1
0
        public static unsafe byte[] encodeVolumeData(ulong intToneVolume, UInt32 dongleID)
        {
#if !USE_BLOW_FISH
            // byte[] result = { 6,125,22,94,21,241,27,119,
            //                   64,253,228,114,115,97,206,149};
#endif
            byte[] result           = new byte[16];
            byte[] BufCode          = new byte[16];
            byte[] keyArr           = Encoding.ASCII.GetBytes(key);
            byte[] defaultEncrypted = writeInkData(intToneVolume, dongleID);
#if USE_DLL
            fixed(byte *byteKey = &keyArr[0])
            {
                fixed(byte *defaultEncode = &defaultEncrypted[0])
                {
                    fixed(byte *bufEncode = &BufCode[0])
                    {
                        Encode(byteKey, key.Length, defaultEncode, bufEncode, 16);
                        Marshal.Copy((IntPtr)bufEncode, result, 0, result.Length);
                    }
                }
            }
#else
            BlowFishClassLibrary.BlowFishClass bFish = new BlowFishClass();
            fixed(byte *byteKey = &keyArr[0])
            {
                fixed(byte *defaultEncode = &defaultEncrypted[0])
                {
                    fixed(byte *bufEncode = &BufCode[0])
                    {
                        bFish.Encode(byteKey, key.Length, defaultEncode, bufEncode, 16);
                        Marshal.Copy((IntPtr)bufEncode, result, 0, result.Length);
                    }
                }
            }
#endif

            return(result);
        }
Beispiel #2
0
        public static unsafe ulong decodeVolumeData(byte[] bytes, out UInt32 dongleID)
        {
#if !USE_BLOW_FISH
            byte[] result = { 6,  125,  22,  94,  21, 241,  27, 119,
                              64, 253, 228, 114, 115,  97, 206, 149 };
#endif
            byte[] result  = new byte[16];
            byte[] BufCode = new byte[16];
            byte[] keyArr  = Encoding.ASCII.GetBytes(key);
#if USE_DLL
            fixed(byte *byteKey = &keyArr[0])
            {
                fixed(byte *encodeData = &bytes[0])
                {
                    fixed(byte *bufDecode = &BufCode[0])
                    {
                        Decode(byteKey, key.Length, encodeData, bufDecode, 16);
                        Marshal.Copy((IntPtr)bufDecode, result, 0, result.Length);
                    }
                }
            }
#else
            BlowFishClassLibrary.BlowFishClass bFish = new BlowFishClass();

            fixed(byte *byteKey = &keyArr[0])
            {
                fixed(byte *encodeData = &bytes[0])
                {
                    fixed(byte *bufDecode = &BufCode[0])
                    {
                        bFish.Decode(byteKey, key.Length, encodeData, bufDecode, 16);
                        Marshal.Copy((IntPtr)bufDecode, result, 0, result.Length);
                    }
                }
            }
#endif
            return(readInkData(result, out dongleID));
        }