using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary;
//aktuelles Datum long jetzt; // unsere Zeitspanne Zeitspanne mySpan; RijndaelManaged RMCrypto = new RijndaelManaged(); byte[] Key = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; byte[] IV = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; Stream s = File.Open(@"key.bin", FileMode.Open, FileAccess.Read, FileShare.Read); jetzt = s.Length; CryptoStream CryptStream = new CryptoStream(s, RMCrypto.CreateDecryptor(Key, IV), CryptoStreamMode.Read); MemoryStream m = new MemoryStream(); int input=0; while(input != -1) { input = CryptStream.ReadByte(); if (input == -1) { break; } m.WriteByte(Convert.ToByte(input)); m.Flush(); } Stream fs = File.Open(@"tmp.str", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); m.WriteTo(fs); m.Flush(); m.Close(); fs.Close(); Stream ms = File.Open(@"tmp.str", FileMode.Open, FileAccess.Read, FileShare.Read); BinaryFormatter bf = new BinaryFormatter(); mySpan = (Zeitspanne)bf.Deserialize(ms); jetzt = DateTime.Now.Ticks; if((mySpan.s <= jetzt) & (jetzt <= mySpan.e)) { this.Visible=true; } else { Response.Redirect("fehler.aspx"); } ms.Close(); s.Close(); CryptStream.Close();
|