/// <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); }
/// <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); }
/// <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)); }
/// <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); }
/// <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; }