示例#1
0
        private bool CheckCRC16(byte[] onePackage)
        {
            Crc32 crc32 = new Crc32();

            byte[] newArray = new byte[onePackage.Length - 4];

            Array.Copy(onePackage, 0, newArray, 0, newArray.Length);

            crc32.AddData(newArray);

            UInt32 crcValue = BitConverter.ToUInt32(onePackage, onePackage.Length - 4);

            return(crc32.Crc32Value == BitConverter.ToUInt32(onePackage, onePackage.Length - 4));
        }
示例#2
0
        public static String GenerateKey(String password)
        {
            String returnKey = "";

            try
            {
                using (Aes myAes = Aes.Create())
                {
                    myAes.Key = Security.Security.getEncryptionKey();
                    myAes.IV  = Security.Security.getEncryptionIV();

                    byte[] toEncryptBytes = Encoding.UTF8.GetBytes(password);

                    Crc32 crc = new Crc32();
                    crc.AddData(toEncryptBytes);
                    byte[] toEncryptBytesCRC = toEncryptBytes.Concat(crc.ToByteArray()).ToArray();

                    using (var encryptor = myAes.CreateEncryptor(myAes.Key, myAes.IV))
                    {
                        using (var ms = new MemoryStream())
                        {
                            using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
                            {
                                cs.Write(toEncryptBytesCRC, 0, toEncryptBytesCRC.Length);
                                cs.FlushFinalBlock();
                            }


                            returnKey = Convert.ToBase64String(ms.ToArray()).TrimEnd('=').Replace('+', '-').Replace('/', '_');
                        }
                    }
                }
            }


            catch (Exception ex)
            {
                Console.WriteLine("\n!!!!!!!!!!!!!! ExecuteSqlCommandForScalar \n!!!!!!!!!!!!!! {0}", ex);
            }

            return(returnKey);
        }