Software Engineer. Stuff and nonsense. The usually short ramblings of Chris McKee.

How to match HMACSHA256 between C# & Python

Things are rarely simple or obvious when working across languages; especially when one is .net. Rather than waste time here's the code, in its long form. Test parameters With a key 182634d8894831d5dbce3b3185c50881 and a message or data value of some random junk with both solutions we should receive d94ed997943420b7d5dfb9b31ae236b7b5225510d8f0314c54ad44fb5fd44a06 C# public string HmacSHA256(string key, string data) { string hash; ASCIIEncoding encoder = new ASCIIEncoding(); Byte[] code = encoder.GetBytes(key); using (HMACSHA256 hmac = new HMACSHA256(code)) { Byte[] hmBytes…

C# logo for stickers + stuff

Back in early 2013 I was pasting stickers all over my Acer, as if it was some sort of third-rate thermal insulation, and I thought to myself, wouldn't it be nice if I could have a C# one. Annoyingly all the C# ones were god awful. But Jeremy Kratz and had kindly made it clear he wasn't bothered about the licence something confirmed recently. Anyhoo I liked it and decided to try and replicate it in…

Handy MongoDB C# Tools

Just a few bits and bobs I've collected up lately. Aggregation is a neat feature in MongoDB and as with most mongo c# stuff it's often a small hurdle to implementing the same query you perform in BSON in the driver language… Sooo just to get you started https://chrismckee.co.uk/mongo-aggregation-in-c/ Quite a good idea to mix this with Profiling so you can watch how it's querying etc... Pipeline Requests I like the pipe…

Simple MongoDB Aggregation in C#

Grouping Data with Count Note: This starts with the 1.10.1 version of the mongo driver; https://www.nuget.org/packages/mongocsharpdriver/1.10.1 the v2 driver wraps the Async methods to syncronous to stay 'compatible' and as such is slower. So running 'synchronous' using v2 would be disadvantaged by the new driver while async with the async driver may have a minor benefit. The async is covered further down using Driver 2.1.…

Validating UK Credit & Debit Cards With LUHN to Type

Note: The regex here is pretty worthless; bin's are listed as ranges and should be handled as such, at the time of writing the ranges were relatively limited and this LUCKILY didn't cause any issues Credit Card validation is a Pain in the Arse *Updated April 2010 But its not going anywhere fast. So I’ve combined two of the scripts I’ve found to meet my needs, added UK credit card data (Maestro/VisaDebit etal)…