Esempio n. 1
0
        /// <summary>
        ///  Dycrypts a nut. 
        /// </summary>
        /// <returns>
        ///  The data encrypted into the nut. 
        /// </returns>
        /// <param name='key'>
        ///  The encryption key. 
        /// </param>
        /// <param name='iv'>
        ///  The initialization vector for the Rijndael cipher. 
        /// </param>
        /// <param name='nut'>
        ///  The nut. 
        /// </param>
        public NutData DecryptNut(byte[] key, byte[] iv, byte[] nut)
        {
            var nutStruct = new NutStruct();
            nutStruct.SetBytes(_aesHandler.Decrypt(key, iv, nut));

            return new NutData(nutStruct);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the nut struct.
        /// </summary>
        /// <returns>
        /// The nut struct.
        /// </returns>
        public NutStruct GetNutStruct()
        {
            var nutStruct = new NutStruct();

            // test for IPv4 or IPv6
            if (Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                nutStruct.Address = BitConverter.ToUInt32(Address.GetAddressBytes(), 0);
            }
            else if (Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
            {
                var sha = SHA256Managed.Create();

                // TODO: I may have to think about how to salt this hash
                var hash = sha.ComputeHash(Address.GetAddressBytes());
                nutStruct.Address = BitConverter.ToUInt32(new ArraySegment <byte>(hash, 0, 8).Array, 0);
            }
            else
            {
                throw new Exception("Unknown IP Address Family");
            }

            nutStruct.Timestamp = (UInt32)(Timestamp - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
            nutStruct.Counter   = Counter;
            nutStruct.Entropy   = BitConverter.ToUInt32(Entropy, 0);

            return(nutStruct);
        }
Esempio n. 3
0
        /// <summary>
        ///  Dycrypts a nut.
        /// </summary>
        /// <returns>
        ///  The data encrypted into the nut.
        /// </returns>
        /// <param name='key'>
        ///  The encryption key.
        /// </param>
        /// <param name='iv'>
        ///  The initialization vector for the Rijndael cipher.
        /// </param>
        /// <param name='nut'>
        ///  The nut.
        /// </param>
        public NutData DecryptNut(byte[] key, byte[] iv, byte[] nut)
        {
            var nutStruct = new NutStruct();

            nutStruct.SetBytes(_aesHandler.Decrypt(key, iv, nut));

            return(new NutData(nutStruct));
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqrlNet.Server.NutData"/> class.
        /// </summary>
        /// <param name='nutStruct'>
        /// Nut struct.
        /// </param>
        public NutData(NutStruct nutStruct)
        {
            // convert the IP address
            Address = new IPAddress(nutStruct.Address);

            // convert the timestamp
            Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            Timestamp = Timestamp.AddSeconds(nutStruct.Timestamp).ToLocalTime();

            Counter = nutStruct.Counter;
            Entropy = BitConverter.GetBytes(nutStruct.Entropy);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqrlNet.Server.NutData"/> class.
        /// </summary>
        /// <param name='nutStruct'>
        /// Nut struct.
        /// </param>
        public NutData(NutStruct nutStruct)
        {
            // convert the IP address
            Address = new IPAddress(nutStruct.Address);

            // convert the timestamp
            Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            Timestamp = Timestamp.AddSeconds(nutStruct.Timestamp).ToLocalTime();

            Counter = nutStruct.Counter;
            Entropy = BitConverter.GetBytes(nutStruct.Entropy);
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the nut struct.
        /// </summary>
        /// <returns>
        /// The nut struct.
        /// </returns>
        public NutStruct GetNutStruct()
        {
            var nutStruct = new NutStruct();

            // test for IPv4 or IPv6
            if(Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                nutStruct.Address = BitConverter.ToUInt32(Address.GetAddressBytes(), 0);
            }
            else if(Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
            {
                var sha = SHA256Managed.Create();

                // TODO: I may have to think about how to salt this hash
                var hash = sha.ComputeHash(Address.GetAddressBytes());
                nutStruct.Address = BitConverter.ToUInt32(new ArraySegment<byte>(hash, 0, 8).Array, 0);
            }
            else
            {
                throw new Exception("Unknown IP Address Family");
            }

            nutStruct.Timestamp = (UInt32) (Timestamp - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
            nutStruct.Counter = Counter;
            nutStruct.Entropy = BitConverter.ToUInt32(Entropy, 0);

            return nutStruct;
        }