예제 #1
0
        public static void Decrypt(ZWaveAES aesEngine, byte[] encKey, byte[] iv, ref byte[] payload)
        {
            string pre = payload.GetHex();

            aesEngine.AES_OFB(encKey, iv, payload, false);
            string after = payload.GetHex();

            "S0 {0} = {1}"._DLOG(after, pre);
        }
예제 #2
0
        /// <summary>
        /// Decrypts the payload.
        /// </summary>
        /// <param name="networkKey">The network key.</param>
        /// <param name="encryptedPayload">The encrypted payload.</param>
        /// <param name="IV">The IV.</param>
        /// <returns></returns>
        public byte[] DecryptPayload(byte[] networkKey, byte[] encryptedPayload, byte[] IV)
        {
            try
            {
                /////////////////////////////
                //byte[] authKey = new byte[16];
                byte[] encKey = new byte[16];

                //byte[] pattern = ZWaveAES.RepeatByte16(0x55);
                //AES.AES_ECB(authData.Key, pattern, authKey); // K_A = AES(K_N,pattern)
                byte[] pattern = ZWaveAES.RepeatByte16(0xAA);
                Engine.AES_ECB(networkKey, pattern, encKey); // K_E = AES(K_N,pattern)
                /////////////////////////////
                byte[] output     = new byte[0];
                byte[] encPayload = new byte[0];

                if (encryptedPayload.Length < 16)
                {
                    output     = ExpandEmptyArray(16);
                    encPayload = ExpandEmptyArray(16);
                }
                else
                {
                    output     = ExpandEmptyArray(encryptedPayload.Length);
                    encPayload = ExpandEmptyArray(encryptedPayload.Length);
                }

                for (int i = 0; i < encryptedPayload.Length; i++)
                {
                    encPayload[i] = encryptedPayload[i];
                }

                Engine.AES_OFB(encKey, IV, encPayload, true);

                byte[] decryptedPayload = new byte[encryptedPayload.Length];
                for (int i = 0; i < encryptedPayload.Length; i++)
                {
                    if (i < encPayload.Length)
                    {
                        decryptedPayload[i] = encPayload[i];
                    }
                }
                return(decryptedPayload);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("SecurityException", ex);
            }
        }