RSA APIs in .NET - Performance comparison

I the last few days I had to take a closer look at cryptographic APIs available in .NET Framework. We’re using RSA + SHA256 to give Office Online hosts opportunity to validate that a request we’re making is actually coming from us. We call that Proof Keys and you can read more about it in public documentation on Office Online Integration Documentation. Just recently we’ve noticed interesting performance problems around signing the data before we make the requests.

.NET had always had RSAServiceCryptoProvider and that’s what we were using. However, when .NET 4.6 shipped a new set of APIs was added, including RSACng. This new RSA Api is backed by Cryptography API: Next Generation in Windows. Turns out that new API is not just easier to use but also much faster.

Read More

Calling a synchronous WCF method asynchronously using ChannelFactory

Asynchronous operation contracts in WCF have been supported since .NET 4.5: you can define service methods to return Task or Task<T> and as you implement your service logic you can use async/await to do the right things when it comes to using IO or other asynchronous operation. You can also use older paradigm called Asynchronous Programming Model (APM) which is based on a pair of Begin*/End* methods.

On the consumer side you can use Visual Studio’s “Add Service Reference” option to generate a client or use ChannelFactory and the service interface to make the calls. All that sounds pretty great, until you run into a situation I recently run into: you have a WCF service which has method you want to implement asynchronously, but you also have some legacy client which for a valid reason has to make the calls in synchronous way. In this post I’ll show you how to call asynchronous WCF operation synchronously (or the other way around) using ChannelFactory.

Read More

Advent of Code 2017 - Day 1 - Inverse Captcha

If you’ve never heard of Advent of Code you should probably check it out. I could try to explain what it is but it’s easier to just quote what Eric Wastl, the organizer wrote about it:

Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme.

I had spare couple hours this weekend and decided to give it a go. But it would be very boring if I was just trying to get the right answers. Instead, I’m using it as an opportunity to get more hands-on experience with F# - something I wanted to do for a long time now but never had a chance. I’m not planning to solve every single puzzle there is, but for the ones I do and find interesting I’m going to post a blog post with my approach. Here comes a little bit about how I solved the first puzzle - Inverse Captcha.

Read More

String.Split and int[] allocations

You might have already heard that it’s not always the best idea to use String.Split unless you really need all the substrings. It might be tempting to use it when you only need the first one, or want to check how many there is but it’s totally unnecessary to allocate all these substrings if all you care about is their count. As I found out pretty recently, it might not be the best idea to use String.Split even if you do want all the substrings. In this post I’ll explain why that’s the case and in what scenarios it might be better to roll your own split routine.

Read More

Monitor hapi based web service with Application Insights

Application Insights is a great tool which allows developers to get better understanding of what’s going on insight their applications and services. It’s platform-agnostic and can be used from pretty much everywhere: from ASP.NET and node.js on the server to client-only applications running in the browser. The documentation is quite good and will help you get started, but there is one thing that I found missing. There is a page describing how to interface Application Insights into node.js application, but it’s using node HTTP server in all the examples. While it might work for some, it doesn’t work for me. The app I’m currently working on uses hapi. In this post I’ll show how in just few lines of code you can instrument hapi-based application and get data flowing into Application Insights.

Read More