Next Generation Cryptography (CNG) for .NET

Droster Lock (Infinite Combination)Last year, Windows Kernel team released a new cryptography libraries called Next Generation Cryptography (CNG). Although it is only available on Windows Vista and Windows Server 2008 kernels so far, I think it is going to replace the CAPICOM with its powerful new implementations.

I quite liked the new CNG libraries as it gets over some limitations of the previous library.

CLR security team released a new project on codeplex called CLR Security for that new cryptography library on .NET. So it is possible to benefit from those libraries in managed worlds as well. For a detailed description be sure to check security blog.

Also, the team is very quick to respond and provide fixes if necessary.

Recent Titles – Common Lisp ebook for free

lisp

I was thinking of reading a Lisp book. I checked the titles and decided to buy,
luckily, it’s freely provided in the Apress’ Practical Common Lisp page.

I doubt that it is done by mistake, because the e-book price is also indicated but anyway there is a free link to download it.

String Stream for .NET

I was working with C++ Standard Template Library (STL) library and when using the StringStream class I felt like we need this for .NET :) Yes we have a great class StringBuilder but we can’t use it as a Stream (because it is not).

Most of the cryptographic classes works with the stream object. I wanted to save the encrypted information as text. Ideally we could use memoryStream but it is not really efficient, because it is bits and we need to build a model for serializing/deserializing as text.

String Stream class (as I call it) is just an ugly but functional wrapper around StringBuilder class as shown some snippets below. I just wanted it to use with encryption and decryption a string. So only the functions needed is there which is enough to use. But I doubt it leaks a little, so use with care if needed.

public class StringStream : Stream
{
        private StringBuilder strBuilder;
        public StringStream()
        {            strBuilder = new StringBuilder();        }
 
        public StringStream(string str)
        {            strBuilder = new StringBuilder(str);        }
 
        public override int Read(byte[] buffer, int offset, int count)
        {
            int howMuchRead = 0;
            for (int i = offset; i < count; i++)
            {
                var actualIndex = i * 2;                
                howMuchRead = i+1;
                if (actualIndex >= strBuilder.Length) 
                {
                    howMuchRead = count;
                    break;
                }                                   
                string s = strBuilder[actualIndex].ToString() + strBuilder[actualIndex + 1].ToString();
                buffer[i] = Convert.ToByte(s,16);
            }
            return howMuchRead;
        }
      public override void Write(byte[] buffer, int offset, int count)
        {            
            for (int i = offset; i < count; i++)
            {
                strBuilder.Append(buffer[i].ToString("x2"));
            }
        }
}

The main magic is happening on reading and writing. each byte is represented as 2 characters in the string. It is using the helper function Convert.ToByte to make it happen.
In the next post I will use it with a symmetric encryption helper class.

My Visual Studio Color Scheme, Friendly IDE

After reading interesting posts about the fonts and colors in Visual Studio, I gave a try to some of them. Because I work quite a lot with Visual Studio, I realized that it is actually very important for the eyes and for productivity. Unfortunately none of the themes have pleased my IDE concept, low contrast, dark background, pale colours, clear type fonts, and follow metaphors.

I also put some time to design and experiment with some fonts and colours. The themes that I found were to dark for me with very high contrast, and the fonts were glowing. 

This theme is still dark but with pale colours. More importantly it follows the metaphors we used to, so it will be OK when discussing with developers. What I mean? You know greenish parts of your code are always comments, or red parts of SQL code is bad (strings for dynamic SQL), as we all used to from visual studio, SQL or any popular IDEs.

One more thing is that when working with F# some of the color features are not the same as C#. So this theme is prepared with the F# projects in mind as well. Also HTML, CSS, JavaScript, and  XAML are formatted following my colour preference.

For fonts I have used DejaVu font with size 10. If Consolas is your favourite font than, it would be better to put on size 9.

Moreover if you use, ReSharper code refactoring tool it has also some colour highlights for it as well. But it is not a problem if you don’t.


C# – F# Scheme

cs fs 

ASPX – HTML – XML Scheme

aspxhtml  xml

Registering Help System for Windows SDK Documentation with Visual Studio

It is explained on Windows SDK blog how to integrate the updated Windows SDK with Visual Studio. However, how about the documentation and help integration with Visual Studio or even the search for API references ? I was using the online SDK until I figured out a work around.

Here are the steps to enable the updated help collections system for Windows SDK with Visual Studio. So at the end, the internal help function will will work with the updated help if necessary.

  1. In Visual Studio , use the menu to navigate to Help -> Index
  2. This will run up Microsoft Document Explorer (and yes it is different than MSDN)
  3. Make sure that the results are unfiltered, in the “Look for” field search for “Collection Manager”,
  4. On the results tree click to collection manager -> Help
  5. Than select the Microsoft Windows SDK Collection checkbox. You can also have additional help integrated with the document explorer.
  6. Update VSCC.

That’s it. Instead of the chm file it is useful to use from Visual Studio with the search capabilities.

Singularity Source Released

Lots of releases happening this week because of Mix 08. For Mix08 releases you might want to check Tim Sneath’s blog.

But beside mix conference a research operating system  from Microsoft Research, “Singularity” is released. The source code can be found in their CodePlex Singularity site. It comes with a research development license.

It will be interesting to see how the academia will implement the new ideas in a managed operating system.