MissionPlanner.MAVLinkInterface.setupSigning C# (CSharp) Method

setupSigning() public method

public setupSigning ( string userseed, byte key = null ) : bool
userseed string
key byte
return bool
        public bool setupSigning(string userseed, byte[] key = null)
        {
            byte[] shauser;
            bool clearkey = false;

            if (key == null)
            {
                clearkey = String.IsNullOrEmpty(userseed);

                // sha the user input string
                SHA256Managed signit = new SHA256Managed();
                shauser = signit.ComputeHash(Encoding.UTF8.GetBytes(userseed));
                Array.Resize(ref shauser, 32);
            }
            else
            {
                shauser = key;
                Array.Resize(ref shauser, 32);
            }

            mavlink_setup_signing_t sign = new mavlink_setup_signing_t();
            if (!clearkey)
            {
                MAV.signingKey = shauser;
                sign.initial_timestamp = (UInt64) ((DateTime.UtcNow - new DateTime(2015, 1, 1)).TotalMilliseconds*100);
                sign.secret_key = shauser;
            }
            else
            {
                MAV.signingKey = new byte[32];
                sign.initial_timestamp = 0;
                sign.secret_key = new byte[32];
            }
            sign.target_component = (byte)compidcurrent;
            sign.target_system = (byte)sysidcurrent;

            generatePacket((int) MAVLINK_MSG_ID.SETUP_SIGNING, sign, MAV.sysid, MAV.compid);

            generatePacket((int) MAVLINK_MSG_ID.SETUP_SIGNING, sign, MAV.sysid, MAV.compid);

            if (clearkey)
            {
                return disableSigning(sysidcurrent, compidcurrent);
            }

            return enableSigning(sysidcurrent, compidcurrent);
        }