# Monday, February 13, 2006

Michael hat das Februar Editorial für das Security Portal von MSDN Germany geschrieben und wirft dabei interessante Vorschläge in den Raum:

  • Wie wäre es, wenn bei den allseits bekannten Programmtests der Fachzeitschriften ein Non-Admin-Test hinzu käme?

  • Wenn ein Programm auch danach beurteilt würde, ob es mit einem ganz normalen Benutzeraccount einwandfrei funktioniert?

  • Meiner Meinung nach: Recht hat er.

    http://www.microsoft.com/germany/msdn/security/februareditorial.mspx

    Monday, February 13, 2006 11:37:59 AM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
    # Friday, February 10, 2006

    really

    Friday, February 10, 2006 5:12:12 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
    # Wednesday, February 01, 2006

    I often get asked things through my messenger and today I decided to start sharing a few lines of the conversations...   

    Frank:

    Is there a way to connect a Validator to an Exception so that the validation summary can be used to display the exception message?

    Lennybacon says:

    1. build a Custom Validator

    Frank:

    Ok

    Lennybacon says:

    2. Use Page_Error or catch to set a "flag" to the Validator

    Lennybacon says:

    3. override the method EvaluateIsValid and return the state of the flag

    Lennybacon says:

    This way the validator (if called on the postback) indicates its validation as true and after the flag is set false.

    Lennybacon says:

    Here is some pseudo-code

    Lennybacon says:

           try

           {

             CriticalOperation();

           }

           catch(MyException e)

           {

             MyValidator.SetInvalid();

             MyValidator.ErrorMessage = "bla bla: " + e.Message;

             Page.Validate();

           }

    Lennybacon says:

           Validator : CustomValidator

           {

              bool flag = true;

              void setInvalid(){flag=false;}

              bool EvulateIsValid()

              {

                   return flag;

              }

           }

     

    http://www.staticdust.net/downloads/Web.ExceptionVisualizer.zip

    ASP.NET | C#
    Wednesday, February 01, 2006 12:05:07 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
    # Tuesday, January 24, 2006

    Tuesday, January 24, 2006 2:23:03 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

    In one of my current projects (yes, there are more at the moment and yes that is the reason why it's a bit quiet around here) i neede to write an encrypted file to the hard disc using DPAPI (Data Protection API). After I unsuccessfully searched the web and the msdn (the sample reads all bytes to the buffer at once - not so nice), I wrote the following sample app:

    using System;

    using System.IO;

    using System.Security.Cryptography;

     

    public class DataProtectionSample

    {

        public static void Main()

        {

            using(MemoryStream ms = new MemoryStream())

            {

                StreamWriter swriter = new StreamWriter(ms);

                swriter.WriteLine("Text to encrypt to file.");

                swriter.Flush();

     

                Console.WriteLine("Protecting data ...");

                DataProtection.Protect("D:\\_temp\\DPAPI.dat", ms, false);

            }

            Console.WriteLine("Unprotecting data ...");

            using(MemoryStream ms2 =

                (MemoryStream)DataProtection.Unprotect("D:\\_temp\\DPAPI.dat", false))
            {

                StreamReader sreader = new StreamReader(ms2);

                Console.WriteLine("");

                Console.WriteLine("Decrypted string: " + sreader.ReadToEnd());

            }

            Console.ReadLine();

        }

    }

     

    public class DataProtection

    {

        private static byte[] _additionalEntropy = { 9, 8, 7, 6, 5 };

        private static int _bufferLength = 1024;

     

        public static void Protect(string filename, Stream stream,

            bool machineLevel)

        {

            if (File.Exists(filename))

            {

                File.Delete(filename);

            }

            using (FileStream fs = new FileStream(filename, FileMode.CreateNew))

            {

                byte[] buffer = new byte[_bufferLength];

                long byteCount;

                stream.Position = 0;

                while ((byteCount =

                   stream.Read(buffer, 0, buffer.Length)) > 0)

                {

                    buffer = ProtectedData.Protect(buffer, _additionalEntropy,

                        ((machineLevel) ? DataProtectionScope.LocalMachine :

                        DataProtectionScope.CurrentUser));

                    fs.Write(buffer, 0, buffer.Length);

                    fs.Flush();

                }

            }

        }

     

        public static Stream Unprotect(string filename, bool machineLevel)

        {

            MemoryStream ms = new MemoryStream();

           

            using (FileStream fs = new FileStream(filename, FileMode.Open))

            {

                byte[] buffer = new byte[_bufferLength + 146];

                long byteCount;

     

                while ((byteCount =

                   fs.Read(buffer, 0, buffer.Length)) > 0)

                {

                    buffer = ProtectedData.Unprotect(buffer, _additionalEntropy,

                        ((machineLevel) ? DataProtectionScope.LocalMachine :

                        DataProtectionScope.CurrentUser));

                    ms.Write(buffer, 0, buffer.Length);

                    ms.Flush();

                }

            }

            ms.Position = 0;

            return ms;

        }

    }

     

     

     

    C# | Projects | Security
    Tuesday, January 24, 2006 2:13:08 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
    # Monday, January 23, 2006
    Monday, January 23, 2006 4:57:23 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
    # Tuesday, January 17, 2006

    MDFExec
     Executing CREATE statements from within Visual Studio 2005

    Snippy
     Editor for creating and modifying Visual Studio 2005 Code Snippets

    WebServer Here Context Menu

    Exclude From Sharepoint

    NDoc Macro

    Cropper
     Screenshot tool

    Ruler

    Folder Size Browser

    Convert.NET
     C# 2 VB.NET Converter

    ChalkTalk

    Mistaya
     LDAP Explorer

    WinMerge

     

     

    Thomas list...

    Event | Misc
    Tuesday, January 17, 2006 11:24:57 AM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
    # Thursday, January 12, 2006

    Thursday, January 12, 2006 10:36:48 AM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  |