# Tuesday, September 28, 2010
I have a content management system developed in visual basic DotNet which I use for some charities I support.  See

http://www.doncasterstgeorges.org.uk
http://www.DoncasterScouts.org.uk and
http://www.26doncaster.org.uk for examples.

Under the hood the data is stored in XML files rather than in a formal database.  I wanted to ensure that the hosted data is secure so have moved from using plain text XML to compressed and encrypted XML.  This has one main benefit - I feel comfortable using an e-mail message with the files attached to back up the data.

This post explains how I did this.  The encryption is using DES which is good enough and symmetric.  The DES service provider is used in many functions and subroutines so I created it as a function.  The compression is using the inbuilt DotNet GZIP compression routine which uses the standard deflate compression.  It seems particularly efficient on XML.

Imports System.Security.Cryptography
Imports System.IO.Compression
Imports System.Xml


    ' Generic code for encrypting XML serialisations


    Public Function DesSP() As DESCryptoServiceProvider
        Dim locDesSP As New DESCryptoServiceProvider
        locDesSP.IV = ASCIIEncoding.ASCII.GetBytes("ABCDEFGH") ' Any 8 characters
        locDesSP.Key = ASCIIEncoding.ASCII.GetBytes("12345678") ' Any 8 characters
        Return locDesSP
    End Function


I opted for a single routine to save any dataset as a compressed and encrypted file since the generic dataset type would suffice.

    Public Sub SaveXMLds(ByVal FileName As String, ByVal DS As DataSet)

        ' This subroutine serialises the specified data set as encrypted XML to the file specified
        ' It works by
        ' 1. creating a CryptoAPITransform using the DESCryptoServiceProvider which is symmetric
        ' 2. creating an filestream writing to a file
        ' 3. creating an encryption stream which uses the CryptoAPITransform to stream to the filestream
        ' 4. creating a compression stream which uses the gZipStream to stream to the encryption stream
        ' 5. creating a streamwriter to write to the encryption stream
        ' 6. creating an XMLwriter to convert the XML serialisation of the data set into a stream
        ' 7. finally, having all the plumbing in place, creating a simple serialisation of the dataset into the XMLwriter

        ' The flow becomes
        ' DataSet -> XML -> XMLWriter -> streamwriter -> Compression stream -> encryption stream -> filestream -> file

        Dim Encryptor As CryptoAPITransform
        Encryptor = DesSP.CreateEncryptor

        Dim OutFile As New FileStream(FileName, FileMode.Create, FileAccess.Write)
        Dim EncryptStream As New CryptoStream(OutFile, Encryptor, CryptoStreamMode.Write)
        Dim CompressStream As New GZipStream(EncryptStream, CompressionMode.Compress)
        Dim OutgoingStream As New StreamWriter(CompressStream)
        Dim OutgoingXML As XmlWriter = XmlWriter.Create(OutgoingStream)

        ' Save the data

        DS.WriteXml(OutgoingXML)

        ' Now time to tidy up afterwards and clean the pipework
        OutgoingXML.Flush()
        OutgoingXML.Close()
        OutgoingStream.Flush()
        OutgoingStream.Close()
        EncryptStream.Flush()
        EncryptStream.Close()

        ' close the file
        OutFile.Close()

    End Sub

For reading the dataset back in I opted for dataset type specific modules, following this example.  The pdsLibrary object in the example is used to cache the data for reads. 

The function is designed to return an XML file if it exists, and then save the XML dataset as a compressed, encrypted file deleting the XML file.  This is to enable the compressed encrypted data to be initially populated.

If the XML version does not exist, the function sets up the streams and reads the data into the typed dataset.


    Dim pdsLibrary As Library

    Public Function GetLibrary() As Library
        Dim fName As String = GetDBPath() + "\Library"
        Dim fNameDS As String = fName + ".zDS"
        Dim fNameXML As String = fName + ".XML"

        If pdsLibrary Is Nothing Then
            pdsLibrary = New Library

            If File.Exists(fNameXML) Then ' an XML file will be used to oferwrite the encrypted file
                pdsLibrary.ReadXml(fNameXML)
                SaveXMLds(fNameDS, pdsLibrary)
                File.Delete(fNameXML)
            ElseIf File.Exists(fNameDS) Then
                Dim Decryptor As CryptoAPITransform
                Decryptor = DesSP.CreateDecryptor
                Dim InFile As New FileStream(fNameDS, FileMode.Open, FileAccess.Read)
                Dim EncryptStream As New CryptoStream(InFile, Decryptor, CryptoStreamMode.Read)
                Dim CompressStream As New GZipStream(EncryptStream, CompressionMode.Decompress)
                Dim IncomingStream As New StreamReader(CompressStream)
                Dim IncomingXML As XmlReader = XmlReader.Create(IncomingStream)
                pdsLibrary.ReadXml(IncomingXML)
            End If
        End If

        GetLibrary = pdsLibrary
    End Function

If you find this useful or have comments, share them with me.

posted on Tuesday, September 28, 2010 12:14:20 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Sunday, August 01, 2010

I have taken delivery of a new gadget - a Huawei E5830 from Play.com.

This little device takes a mobile broadband SIM and creates a mini WiFi hotspot.  It came configured for the 3 network but after unlocking (courtesy of Zibri http://www.zibri.org/2010/05/e5830-free-unlock-released.html) while travelling on an East Coast train it works well on Vodafone.  I just needed to change the APN details.

APN - internet

Username - web

Password - web

All in all I am inpressed.  It works well with the iPod touch.

posted on Sunday, August 01, 2010 8:26:38 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Sunday, June 20, 2010
From the BBC during Brazil V Ivory Coast What did Barnsley say when they went up to the Premiere League - Just =20 like watching Brazil. This us just like watching Barnsley!
posted on Sunday, June 20, 2010 8:05:50 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1] Trackback
# Wednesday, June 16, 2010
On Forlan during the South Africa - Uruguay match

He could play in his slippers   
posted on Wednesday, June 16, 2010 8:07:13 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Saturday, June 12, 2010
Now I have an iPod touch I am very interested to have a wireless connection.  Increasingly I am irritated by the practice of hotels (in particular) to charge not only for a connection, but for each device.  In Brazil I took two laptops and chose a pay per byte tarriff because a pay per day tarrif would have only worked on one device.

The iPod motiviated me to find a solution, and I was very surprised to find Microsoft have provided the answer in Windows 7 for machines with a certified WiFi driver.  In short, any Windows 7 machine (except ones running starter edition) can easily be turned into a full wireless access point (not just establishing an ad-hoc network).

In this posting, I will describe the manual way of setting this up, and then link to software to do this for you.

Doing it by hand

The key to this is Microsoft's addition of a Virtual wifi miniport adapter (thanks to http://bink.nu/news/windows-7-as-an-wifi-accesspoint.aspx for a simple guide).
Step 1 - open a command prompt with administrative rights.  This is not simply open a command promp as an administrator - you need to right click on "Command Prompt" (usually found in the accessories folder of the start menu) and choose Run As Administrator.
Step 2 - allow a hosted network with the command
netsh wlan set hostednetwork mode=allow ssid=MyNetworkName key=sesamestreet     
The ssid and password should be changed Smile
Step 3 - the created network needs to share onward access.  I won't explain here but it is covered in Steven Bink's article.  You need to choose the outbound connection (e.g wired lan, wireless on the same hardware or a 3G connection)
Step 4 - change the configuration so that the virtual network adapter is limited to using IP.  Again  I won't explain here but it is covered in Steven Bink's article
Step 5 - turn it on.  Again in a command prompt with administrative rights
netsh wlan start hostednetwork   

 

A software utility to help

Now to the software.  I am sure there is more, but I chose this OpenSource project:

http://virtualrouter.codeplex.com/

This allows easy setup of the virtual access point and then displays the devices connected.

Some thoughts.
Microsoft have been quite clever - they are able to support connecting devices to the Windows platform, such as Zune and Windows Mobile 7.  They have limited the functionality to WPA encrypted networks but are ensuring drivers should be able to support Wi-Fi Direct when it becomes a standard.
See also Errata Security
posted on Saturday, June 12, 2010 8:54:23 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Sunday, June 06, 2010
I have a new iPod touch and I have to say I am very impressed. I am not a massive Apple evangelist and regularly make fun of people with their nice shiny macs costing twice as much as any PC I would buy, though I did use a mac at college before it became a mac classic.
So for first thoughts:
  • It works well as an iPod including playback with my bluetooth headphones but doesn't support the headphones' control functions and doesn't support the microphone
  • The keyboard in portrait mode is just a bit too fiddly and I haven't found a way to view mobile web pages in landscape
  • The browser works well and I like the fact it doesn't support flash player E-mail setup for exchange was very good though I would like to be able to set up two exchange servers
  • How on earth does it do the location services on wifi? Works rediculously well.
Would I pay an extra £250-£300 for an iPod with camera, GPS, microphone and 3g. No, but if work offered it as an option I would go for it.
posted on Sunday, June 06, 2010 10:38:07 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Wednesday, June 02, 2010
I am surprised to hear (when listening to Dirk Gently's Holistic Detective Agency) that the cat flap was invented by Isaac Newton.  Wikipedia agrees.
Cat flap - Wikipedia, the free encyclopedia
He did not invent gravity - apparently it had already been invented by someone.

posted on Wednesday, June 02, 2010 5:10:56 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Monday, May 10, 2010
I was in the ISO TC215 working group meeting today in wet and cold Rio de Janeiro.  A highlight was the floating of this quote from Philip K Dick.

Reality is that which, when you stop believing it, doesn't go away. 
Quite a powerful thought from the author of one of my favourite books - "Do androids dream of electric sheep?"
posted on Monday, May 10, 2010 3:25:55 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Thursday, April 15, 2010
I am grateful to Andy Wiesenthal of Kaiser Permanente  for this reminder.  Andy wrote:
I would like to describe a rule that I learned long ago from a wise primary care doctor working on our first electronic health record in Kaiser Permanente in Colorado. His name was Ed McAuliffe, and he reminded us of his principle often enough that we all took to calling it “McAuliffe’s Rule.” Whenever we were fretting about the (often important) flaws in the electronic solution we were considering at any particular moment, Ed would often say “yes, but isn’t this still better than what we do now?

So often we forget quite how flawed current clinical record management is.
posted on Thursday, April 15, 2010 11:12:39 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Tuesday, February 23, 2010
Aome americans introduced me to the term Marchetecture.  This fusion of marketing and archetecture is designed to show how some large equipment manufacturers use their marketing brochures to describe an implicit (if not real) archetecture.
Personally I hate it.

posted on Tuesday, February 23, 2010 8:02:00 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback