Generating Data Type Classes from XML

I was shown a nice trick recently in Visual Studio that I never realised existed. The technique is an easy way to create a C# class from an XML or JSON document. Have you ever been in the situation where you are taking an XML or JSON feed from one system and need to integrated it into a project you are working on? I have plenty of times and creating the data type from that XML so you can de-serialize it back can be a pain.

Generating Data Type Classes from XML

Generating Data Type Classes from XML

At first I thought I must be the only person who doesn’t know this, but on discussing it with some team members, they hadn’t hear of it either. Lets take a look at an example with XML. I have taken an example excerpt of XML from the W3CSchools website.

<breakfast_menu>
    <food>
        <name>Belgian Waffles</name>
        <price>$5.95</price>
        <description>
            Two of our famous Belgian Waffles with plenty of real maple syrup
        </description>
        <calories>650</calories>
    </food>
    <food>
        <name>Strawberry Belgian Waffles</name>
        <price>$7.95</price>
        <description>
            Light Belgian waffles covered with strawberries and whipped cream
        </description>
        <calories>900</calories>
    </food>
    <food>
        <name>Berry-Berry Belgian Waffles</name>
        <price>$8.95</price>
        <description>
            Light Belgian waffles covered with an assortment of fresh berries and whipped cream
        </description>
        <calories>900</calories>
    </food>
    <food>
        <name>French Toast</name>
        <price>$4.50</price>
        <description>
            Thick slices made from our homemade sourdough bread
        </description>
        <calories>600</calories>
    </food>
    <food>
        <name>Homestyle Breakfast</name>
        <price>$6.95</price>
        <description>
            Two eggs, bacon or sausage, toast, and our ever-popular hash browns
        </description>
        <calories>950</calories>
    </food>
</breakfast_menu>

If you take the above XML and place it into the clip board. Then create or open an existing visual studio project. Goto the Edit Menu and select “Paste Special” and then “Paste XML as Classes“. This will create a set of classes that represents the XML data structure.

Continue reading

Posted in Coding, Visual Studio | Tagged , , | Leave a comment

Interview on the Syncfusion Blog

Syncfusion recently did a quick interview with me for their blog. I was interviewed because I am an author on their Succinctly series of e-books.

Stephen Haunts Interview on the Syncfusion Blog

Stephen Haunts Interview on the Syncfusion Blog

The interview is based around my recently book release called “Cryptography in .NET Succinctly“. The book description is as follows:

Cryptography is used throughout software to protect all kinds of information, from emails, to passwords, to credit card data, and more. It goes beyond encrypting data, and provides assurances of confidentiality, informational integrity, and non-repudiation. With Cryptography in .NET Succinctly by Stephen Haunts, you will learn various methods to implement cryptography in .NET apps, including using the SHA, AES, and RSA hash algorithms, leveraging symmetric and asymmetric encryption, and creating digital signatures.

Cryptography in .Net by Stephen Haunts

Cryptography in .Net by Stephen Haunts

Table of Contents

What is Cryptography?

Cryptographic Random Numbers

Hashing Algorithms

Password Storage

Symmetric Encryption

Asymmetric Encryption

Hybrid Approach (RSA+AES)

Digital Signatures

Posted in Commentary, Cryptography, Security | Tagged , , | Leave a comment

Using Music to Focus

Recently, Carl Frankin, software developer, musician and presenter on the popular programming podcast DotNet Rocks, released a music album aimed a software developers. The album is called Music to Code By and comprises of 3 x 25 minute long music tracks.

The idea behind the album is that each track is the length of one pomodoro and you listen to the music and focus on your work for 25 minutes and then take a break. After this break, you work for another 25 minutes. The music is designed help you concentrate and filter out any distractions to allow you to focus.

Carl Franklin - Music to Code By

Carl Franklin – Music to Code By

I purchased a copy of the album last week. It costs $20 dollars and I thought I would give it a try. For this price you get the CD, which should turn up at some point soon and a digital copy of the album. If I am honest I am not bothered about the physical disc. I will probably look at it and think “ohhh shiny” and then put it on a shelf. I haven’t bought a real CD for about 8 years. It would be good to see a digital only offering that is cheaper for some people, but it’s not a big deal.

I have tried the album out on a project last week. It wasn’t a coding project, but I needed to complete my 2nd e-book for Syncfusion. I used this album to help me focus and get the job completed. It took me 3 days to complete the project.

Did it work?

Yeah, the album definitely helped me focus and split my work down to 25 minute intervals. The music isn’t what I would normally listen too and I would describe it as a series smooth funk tracks, but to get the job done it certainly helped. I wouldn’t use this all the time as the tracks could get repetitive after a while and I normally like to listen to film soundtracks whilst I am working, but if I have a deadline looming and I really need to just focus, then I would use this album as I am not as attached to the music as I would be with my favourite film soundtrack. I think that’s a key point actually because I am not actually listening to the music I am just using it block out the environment around me, where as with a film soundtrack (and I like action scores) part of my brain is also listening to the music.

Coffitivity and Background Sounds

I was discussing this with a colleague of mine and he told be about a site that he uses called Coffitivity. This is a completely different twist using music or sound to focus with. What is presented here are streamed recordings of ambient cafe / coffee shop sounds. Imagine you are sitting in Starbucks doing some work whilst enjoying a coffee with all the noises of the cafe in the background. That is exactly what this is.

Coffitivity - Ambient cafe sounds

Coffitivity – Ambient cafe sounds

I am listening to a track on it as I write this post and I really like it. I am not thinking about the noise but it is helping me block out the surrounding work environment around me.

Which is Best?

I think it would be unfair to say whether Coffitivity is better than Music to Code By or the other way around. They are both different. I could see myself using coffitivity a lot more for general work as the ambient sounds are quite soothing, where as if I am up against it and I really need to get something done for a deadline, I can see myself using Music to Code By as my musical weapon of choice.

As with anything, this all subjective, what works for me wont necessarily work for you, but I would give both a try. Coffitivity is free to try out with a few tracks, so you should definitely give it ago. There is a premium version you can pay for to get access to more tracks. Music to Code By costs $20. Both are worth checking out.

Posted in Commentary | Tagged | Leave a comment

“Cryptography in .NET Succinctly” Book Released

Cryptography in .Net by Stephen Haunts

Cryptography in .Net by Stephen Haunts

My first book Cryptography in .NET Succinctly has now been released by Syncfusion Inc. Even better news is that this book is FREE of charge. You just sign up with an email address and download the book. This book is useful to any developer who creates software solution in Microsoft .NET for the enterprise.

The books synopsis is as follows:

Cryptography is used throughout software to protect all kinds of information, from emails, to passwords, to credit card data, and more. It goes beyond encrypting data though, and provides assurances of confidentiality, informational integrity, and nonrepudiation. With Cryptography in .NET Succinctly by Stephen Haunts, you will learn various methods to implement cryptography in .NET apps, including using the SHA, AES, and RSA algorithms, leveraging symmetric and asymmetric encryption, and creating digital signatures.

The table of content is :

  1. What is Cryptography?
  2. Cryptographic Random Numbers
  3. Hashing Algorithms
  4. Password Storage
  5. Symmetric Encryption
  6. Asymmetric Encryption
  7. Hybrid Approach (RSA+AES)
  8. Digital Signatures

The following people worked on this book.

Author : Stephen Haunts

Technical Reviewer : Jim Perry

Copy Editor : Suzanne Kattau

Acquisitions Coordinator : Hillary Bowling

Proofreader : Graham High

Posted in Coding, Commentary, Cryptography, Security | Tagged , , , , | Leave a comment

Agile Fundamentals Course Now Live on Pluralsight

My new course, Agile Fundamentals is now live with Pluralsight. The course description is as follows :

In Agile Fundamentals, we explore how working on an Agile project has benefits for your development team, your end users, and your organization as a whole. This course starts by exploring the more traditional waterfall process, and then covers why running an Agile team is a good idea. This course is ideal for software developers, project managers, software leadership, or anyone that would have an interest and gain benefit from running an Agile project and delivering maximum value early to your customers.

The course is split into the following modules :

1. Introduction

2. Waterfall Development and It’s Problems

3. What is Agile all About?

4. Common Agile Misconception

5. The Advantages and Disadvantagesof Agile

6. Extreme Programming

7. Scrum

Posted in Agile, Commentary, Pluralsight | Tagged , , | 1 Comment

Cryptography in .NET Talk : Slides and Sample Code

Cryptography in .NET Talk at Dot Net Notts

Cryptography in .NET Talk at Dot Net Notts

Today I did a talk on Cryptography in .NET. The talk synopsis is as follows :

Data security is something that we as developers have to take seriously when developing solutions for our organizations. Cryptography can be a deeply complicated and mathematical subject but as developers we need to be pragmatic and use what is available to us to secure our data without disappearing down the mathematical rabbit hole.

Cryptography in .NET Talk at the DotNet Notts User Group by Stephen Haunts

Cryptography in .NET Talk at the DotNet Notts User Group by Stephen Haunts

In this talk Stephen Haunts will take you through what is available in the .NET framework for enterprise desktop and server developers to allow you to securely protect your data to achieve confidentiality, data integrity and non-repudiation of exchanged data. Stephen will cover the following:

  • Cryptographically secure random number generation
  • Hashing and Authenticated Hashes
  • Symmetric Encryption with DES, TripleDES, and AES
  • Asymmetric Encryption with RSA
  • Hybrid Encryption by using Symmetric and Asymmetric encryption together.
  • Digital Signatures

You can now download the Slides and Sample Code in C# from this talk. If you have any questions about the talk or the subject matter then please feel free to leave a comment on this article or contact me via the contact form on this blog.

Posted in Coding, Commentary, Cryptography | Tagged , , | Leave a comment

RC4 Stream Cipher

I recently started to look at some other cryptography ciphers outside what is included in my development platform of choice, .NET, and started reading up on RC4. RC4 is a stream cipher.

Stream Ciphers

A stream cipher is a symmetric key cipher where plain-text digits are combined with a pseudo-random cipher digit stream (key-stream). In a stream cipher each plain-text digit is encrypted one at a time with the corresponding digit of the key-stream, to give a digit of the cipher-text stream. With a stream cipher a digit is typically a bit and the combining operation an exclusive-or (XOR).

RC4 Stream Cipher

RC4 Stream Cipher

The pseudo-random key-stream is typically generated serially from a random seed value using digital shift registers. The seed value serves as the cryptographic key for decrypting the cipher-text stream.

Stream ciphers represent a different approach to symmetric encryption from block ciphers. Block ciphers operate on large blocks of data n a fixed block size. Stream ciphers typically execute at a higher speed than block ciphers and have lower hardware complexity.

RC4 Stream Cipher

In cryptography, RC4 (also known as ARC4 or ARCFOUR meaning Alleged RC4) is the most widely used software stream cipher and is used in popular protocols such as Transport Layer Security (TLS) (to protect Internet traffic) and WEP (to secure wireless networks). While remarkable for its simplicity and speed in software, RC4 has weaknesses that argue against its use in new systems.

RC4 was designed by Ron Rivest of RSA Security in 1987. RC4 was initially a trade secret, but in September 1994 a description of it was anonymously posted to a mailing list. The leaked code was confirmed to be genuine as its output was found to match that of proprietary software using licensed RC4. Because the algorithm is known, it is no longer a trade secret. The name RC4 is trademarked, so RC4 is often referred to as ARCFOUR or ARC4 (meaning alleged RC4) to avoid trademark problems.

Continue reading

Posted in Coding, Cryptography | Tagged , , | Leave a comment

Useful Articles on Microsofts HoloLens

Whilst on my quest for more information on HoloLens I came across some useful articles written by some early testers of the device, and also the cover feature for Februaries edition of Wired with Microsoft CEO Satya Nadella. These articles give lots of great insight into the new HoloLens device and it’s design and possible applications.

Microsoft HoloLens

Microsoft HoloLens

Microsoft HoloLens hands on: It’s early, but it’s already nifty

Project HoloLens: Our Exclusive Hands-On With Microsoft’s Holographic Goggles

Microsoft in the age of Satya Nadella

Posted in Commentary, Windows 10 | Tagged , | Leave a comment

Windows 10, the Spartan Browser and HoloLens

The other day Microsoft made some interesting announcements that have started to whip up a frenzy in the tech community. The main ones that I find interesting are :

  • Windows 10 to be offered Free for a year
  • The new Spartan web browser
  • Hololens holographic glasses

Microsoft announced many other things, of which you can get a summary in the video below, but the above points are the ones that really interested me.

Windows 10 to be Offered Free for a Year

Windows 10 is shaping up to be a great new version of Windows where they are correcting a lot of the things that people hated about Windows 8 to create a more cohesive operating system between the desktop and mobile platforms. Microsoft realises that they did a lot of damage to their reputation with Windows 8 (although I didn’t think it was that bad to be honest) so to get people to adopt the new version they have announce that they will give it away for free for Windows 7 and 8 users for a year after it’s release.

Windows 10 New Start Menu

Windows 10 New Start Menu

This is good news as I think it would be a hard sell to convince people who are non MSDN subscribers to part with their cash to upgrade.

The New Spartan Web Browser

There have been rumours flying around for a while now that Microsoft is going to deprecate their Internet Explorer browser and replace it with a new experience, and it is now official. They have announced a new lightweight, and higher performance browser called Spartan.

Microsoft Spartan

Microsoft Spartan

During yesterday’s Windows 10 demonstration, Microsoft showed off how users will be able to annotate and share Web pages using Spartan, as leaks previously indicated would be the case. They also showed Spartan’s built-in reading experience capabilities and the expected Cortana integration.

Also previously leaked, Spartan will work on Windows Phones, tablets and PCs. This will make Spartan the replacement for Internet Explorer including the version that shipped with Window 8 both on the desktop and tablet devices.

Hololens Holographic Glasses

The real exciting news to me, and something I certainly wasn’t expecting, was Microsoft’s announcement of the Hololens Holographic Glasses. This device is just unbelievably cool. Essentially, when you look through the glasses you see your environment as though you was wearing a normal pair of glasses, but the device will blend 3D graphic into your environment as it you was seeing an actual holographic image.

Windows Hololens

Windows Hololens

This is in contrast to a device like the Oculus Rift where you are immersed into a completely 3D environment. What is interesting is that the Hololens is a completely untethered device as there is no cable to your computer or games console.

Microsoft had some interesting demos for this device, including controlling a Mars rover, augmented instructions for doing DIY, and a game of Minecraft. It’s early days, but the potential for this is huge. I can’t wait to get my hands on one and try some development with it.

One thing I am keen to know is what is the battery life like? This is something that will truly determine its usefulness. If it is low (around an hour) then that will seriously compromise how useful this device will be. If it can keep going for 6+ hours then this will be much more useful, especially for applications outside gaming where staff may have to wear this as part of a shift.

The possibilities are endless for this device and I am truly excited to see where this goes. I just hope Microsoft hurries up and makes it available to us developers as I want one!! I am in full on gear lust mode now!

Microsoft Hololens Minecraft Demo

Microsoft Hololens Minecraft Demo

There are no firm release dates yet, but there is supposed to be more information at Aprils Build conference in San Francisco. The following video talks about some of the possibilities with Hololens.

Microsoft in my opinion is making all the right moves. Windows 10 is shaping up to be a great new version of Windows, and their new Browser will hopefully cure all the ills of Internet Explorer. The future of being a developer in the Microsoft eco-system has never looked so good.

Posted in Commentary, Windows 10 | Tagged , | 1 Comment

Cryptography in .NET Talk at the DotNet Notts Usergroup

Originally posted on Stephen Haunts { Coding in the Trenches }:

Meetup at DotNet Notts Meetup at DotNet Notts

On January 26th 2015 I will be doing a talk at the DotNet Notts usergroup in Nottingham UK. The talk will be on Pragmatic Cryptography in .NET. The talk synopsis is as follows.

Data security is something that we as developers have to take seriously when developing solutions for our organizations. Cryptography can be a deeply complicated and mathematical subject but as developers we need to be pragmatic and use what is available to us to secure our data without disappearing down the mathematical rabbit hole.

In this talk Stephen Haunts will take you through what is available in the .NET framework for enterprise desktop and server developers to allow you to securely protect your data to achieve confidentiality, data integrity and non-repudiation of exchanged data. Stephen will cover the following:

Cryptographically secure random number generation.

Hashing and Authenticated Hashes.

Symmetric Encryption with DES, TripleDES…

View original 22 more words

Posted in General | Leave a comment