Exemple #1
0
        /// <summary>
        ///     Verify MD5 authentication of a packet.
        /// </summary>
        /// <param name="authKey">Authentication key (not password)</param>
        /// <param name="authenticationParameters">Authentication parameters extracted from the packet being authenticated</param>
        /// <param name="wholeMessage">Entire packet being authenticated</param>
        /// <returns>True on authentication success, otherwise false</returns>
        public bool authenticateIncomingMsg(byte[] authKey, byte[] authenticationParameters, MutableByte wholeMessage)
        {
            var md5    = new HMACMD5(authKey);
            var hash   = md5.ComputeHash(wholeMessage, 0, wholeMessage.Length);
            var myhash = new MutableByte(hash, 12);

            if (myhash.Equals(authenticationParameters))
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        ///     Verify SHA-1 authentication of a packet.
        /// </summary>
        /// <param name="authKey">Authentication key (not password)</param>
        /// <param name="authenticationParameters">Authentication parameters extracted from the packet being authenticated</param>
        /// <param name="wholeMessage">Entire packet being authenticated</param>
        /// <returns>True on authentication success, otherwise false</returns>
        public bool authenticateIncomingMsg(byte[] authKey, byte[] authenticationParameters, MutableByte wholeMessage)
        {
            var sha    = new HMACSHA1(authKey);
            var hash   = sha.ComputeHash(wholeMessage);
            var myhash = new MutableByte(hash, 12);

            sha.Clear(); // release resources
            if (myhash.Equals(authenticationParameters))
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Verifies correct MD5 authentication of the frame. Prior to calling this method, you have to extract authentication
        /// parameters from the wholeMessage and reset authenticationParameters field in the USM information block to 12 0x00
        /// values.
        /// </summary>
        /// <param name="userPassword">User password</param>
        /// <param name="engineId">Authoritative engine id</param>
        /// <param name="authenticationParameters">Extracted USM authentication parameters</param>
        /// <param name="wholeMessage">Whole message with authentication parameters zeroed (0x00) out</param>
        /// <returns>True if message authentication has passed the check, otherwise false</returns>
        public bool authenticateIncomingMsg(byte[] userPassword, byte[] engineId, byte[] authenticationParameters, MutableByte wholeMessage)
        {
            byte[]  authKey = PasswordToKey(userPassword, engineId);
            HMACMD5 md5     = new HMACMD5(authKey);

            byte[]      hash   = md5.ComputeHash(wholeMessage, 0, wholeMessage.Length);
            MutableByte myhash = new MutableByte(hash, 12);

            if (myhash.Equals(authenticationParameters))
            {
                return(true);
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// Verifies correct SHA-1 authentication of the frame. Prior to calling this method, you have to extract authentication
        /// parameters from the wholeMessage and reset authenticationParameters field in the USM information block to 12 0x00
        /// values.
        /// </summary>
        /// <param name="userPassword">User password</param>
        /// <param name="engineId">Authoritative engine id</param>
        /// <param name="authenticationParameters">Extracted USM authentication parameters</param>
        /// <param name="wholeMessage">Whole message with authentication parameters zeroed (0x00) out</param>
        /// <returns>True if message authentication has passed the check, otherwise false</returns>
        public bool authenticateIncomingMsg(byte[] userPassword, byte[] engineId, byte[] authenticationParameters, MutableByte wholeMessage)
        {
            byte[]   authKey = PasswordToKey(userPassword, engineId);
            HMACSHA1 sha     = new HMACSHA1(authKey);

            byte[]      hash   = sha.ComputeHash(wholeMessage);
            MutableByte myhash = new MutableByte(hash, 12);

            sha.Clear(); // release resources
            if (myhash.Equals(authenticationParameters))
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Verify SHA-1 authentication of a packet.
        /// </summary>
        /// <param name="authKey">Authentication key (not password)</param>
        /// <param name="authenticationParameters">Authentication parameters extracted from the packet being authenticated</param>
        /// <param name="wholeMessage">Entire packet being authenticated</param>
        /// <returns>True on authentication success, otherwise false</returns>
        public bool authenticateIncomingMsg(byte[] authKey, byte[] authenticationParameters, MutableByte wholeMessage)
        {
            HMACSHA1 sha = new HMACSHA1(authKey);

            byte[]      hash   = sha.ComputeHash(wholeMessage);
            MutableByte myhash = new MutableByte(hash, 12);

#if !NETCOREAPP11 && !NETSTANDARD15
            sha.Clear();             // release resources
#else
            sha.Dispose();
#endif
            if (myhash.Equals(authenticationParameters))
            {
                return(true);
            }
            return(false);
        }