Archive for the ‘Uncategorized’ Category

Evaluate C# with C# using #Roslyn

Having code that evaluates code is a bit of an unusual ask, but perhaps, you want to have a super-configurable system, where you can dynamically execute user code, giving full flexibility over the functionality of your system. Obviously this opens security issues, but let’s imagine you are in a secure, trusted environment

So, this is where Roslyn comes in, Which you can load by grabbing the NuGet package using “Install-Package Microsoft.CodeAnalysis.CSharp.Scripting”. Then, you can run a very simple command such as;

var result = CSharpScript.EvaluateAsync("1 + 3").Result;

All very simple, however, let’s say you want to run more complex code. Here, for example, to run some code to get the user’s IP address. I’ve moved this out to a seperate file, called Sample.txt, and set the build option to copy always, so I can write the user code in a different location to the interpreting code.

var wc = new WebClient();
return wc.DownloadString("");

If you try to run this as a script, it borks, because it can’t locate WebClient, and fully qualifying it, by saying System.Net.WebClient doesn’t work either, because it can’t locate System.Net either, so you need to add a bit more as follows –

var scriptOptions = ScriptOptions.Default;
var asmWebClient = typeof(WebClient).Assembly;
scriptOptions = scriptOptions.AddReferences(asmWebClient);
scriptOptions = scriptOptions.AddImports("System.Net");
var sample = File.ReadAllText("sample.txt");
var result = CSharpScript.EvaluateAsync(sample, scriptOptions).Result;

This grabs the relevant assembly for WebClient, and then adds both the reference, and the import to the script. Once it executes, it can find the WebClient class, and the code runs.

GitHub Repo here:

Categories: Uncategorized

#Excel tip: Formula to cross check ledger transactions

This is a real time saver, and I hope it’s useful to someone else.

If you have a typical “ledger” type spread sheet, with columns, payments in, payments out and balance – based on the image above. Perhaps this has been entered manually, or perhaps it’s been OCR’d from paper, there could be errors in it, and it can take alot of time to manually check each number.

In the example above you can see there must be an issue with the value in Cell D4, since the Balance does not reflect the value. However, getting excel to highlight this error would allow you to manually check that one cell, not every value on the spreadsheet.

So, I added a new cell in G3 with the value =$E$2+SUM($D$3:D3)-SUM($C$3:C3) and copied this for each row in the spreadsheet. Then added a conditional formatting rule; of =$G1<>$E1

Which then highlights what the Balance should be for each row, and highlights it, if the balance is different to that stated. In this case, you can see that after a point, the projected Balance diverges from the stated balance, indicating the row at which an inaccuracy is present.

Correcting this value, and the projected balance now matches the stated balance, without having to check every single value on the spreadsheet.

Categories: Uncategorized

Add a #FingerPrint reader to a C# WinForms app

Probably a good way to add extra security to a Windows Form app, just to make sure that there is a real human user infront of the screen, and it’s not some bot trying to interact with your software, is to add a Fingerprint / “Windows Hello” login. Of course, in the real world, generally the attacker would probably try to de-compile your software and try to attack whatever underlying API you are using. However, this is a very visible security feature, and if you’re looking for a super-quick security addition, then, this may be an interesting addition.

Windows Hello is a biometric authentication feature that allows users to log into their Windows device using a fingerprint scanner, facial recognition, or other biometric methods, rather than a password.

Some potential use cases for including Windows Hello in a WinForms app include:

  • Secure login: By using a fingerprint scanner or other biometric method, you can add an additional layer of security to your app and make it more difficult for unauthorized users to access the app.
  • Convenience: Allowing users to log in with a fingerprint or other biometric method can make the login process more convenient for them, as they don’t have to remember a password or enter it manually.
  • Compliance: Depending on the nature of the app and the industries it serves, biometric authentication may be required by compliance regulations or industry standards.
  • User experience: For some users, biometric authentication is a preferred way to interact with their devices, and they feel more secure with that kind of security.
  • Protecting sensitive data: If your app handles sensitive information, such as financial data or personal information, biometric authentication can help ensure that only authorized users have access to this information.

Here is a link to a public GitHub Repo that shows a simple example of this in action:

The Key code being;

var supported = await KeyCredentialManager.IsSupportedAsync();
if (!supported) return;
var result =
	await KeyCredentialManager.RequestCreateAsync("login",
if (result.Status == KeyCredentialStatus.Success)
	MessageBox.Show("Logged in.");
	MessageBox.Show("Login failed.");
Categories: Uncategorized

AvatarAPI now includes #GitHub as a source is an API that allows you get images, names , and sometimes addresses from an email address, depending on what source / provider is used.

Today, GitHub is the latest addition to the source list, which means that anyone with a public email address on their GitHub profile can be searched, returning the avatar icon, and the account name.

A handful of potential use cases for this API are as follows;

  1. Social media and networking apps can use the API to automatically populate user profiles with their contact’s profile pictures and names.
  2. Email clients can use the API to display the sender’s profile picture and name in the email’s header.
  3. Customer relationship management (CRM) software can use the API to associate a customer’s email address with their profile picture and name.
  4. Online marketplaces and e-commerce platforms can use the API to show a buyer’s profile picture and name on their account page.
  5. Collaboration and productivity tools can use the API to display a team member’s profile picture and name in a shared document or project management platform.
  6. Security and authentication systems can use the API to verify the identity of a user based on their email address and associated profile picture and name.
  7. Online gaming and virtual reality platforms can use the API to display a player’s profile picture and name in-game or on a leaderboard.
  8. Educational and training platforms can use the API to associate a student’s email address with their profile picture and name in a virtual classroom.
Categories: Uncategorized

Checking a Spanish #VAT number using the #VIES webservice in C#

Checking EU VAT numbers using the VIES webservice has some quirks, for example, in Germany, only the validity of the number can be verified, and in Spain, although the company name and address are not exposed, the API can be used to verify them against provided details, for this, a different service method needs to be used for Spain, than for other countries;

TL; DR; here is the Github Repo showing the code in c#

Checking a VAT number in Spain can be done by using the European Union’s VAT Information Exchange System (VIES). VIES is a web-based system that allows businesses and tax authorities in the EU to verify the validity of VAT numbers assigned to companies in other EU member states.

To check a VAT number in Spain using VIES, you would need to make a SOAP web service request to the VIES web service endpoint, passing in the VAT number you wish to validate as a parameter. The request would be sent to the VIES service over HTTPS, ensuring the data transmitted is secure.

The VIES service would then respond with a validation result indicating whether the VAT number is valid or not. If the VAT number is valid, the response would also include the country code of the member state that issued the VAT number. The VIES service does not expose the name or address of the company.

Added in the code is a inspector that prints to the console the XML being sent and received, for use in Postman, or another client that needed to POST the XML via HTTP rather than SOAP; which would be;

Sample Request

<s:Envelope xmlns:s="">
  <s:Body xmlns:xsi="" xmlns:xsd="">
    <checkVatApprox xmlns="">
      <traderName>Rodrisa Automoviles</traderName>
      <traderCompanyType />
      <traderStreet>Avda. Reina Victoria</traderStreet>
      <requesterCountryCode />
      <requesterVatNumber />

Sample Response

<env:Envelope xmlns:env="">
        <ns2:checkVatApproxResponse xmlns:ns2="">
            <ns2:traderName>Rodrisa Automoviles</ns2:traderName>
            <ns2:traderStreet>Avda. Reina Victoria</ns2:traderStreet>
Categories: Uncategorized

Clearing out #AWS #Cloudwatch in C# – Coded with help from #ChatGPT

If you’re like me, you use AWS Cloudwatch when testing and debugging your Lambda functions on AWS, and then whenever your code is working, you end up leaving them in, “just in case” – Of course, that means you ignore them, until you get a bill from AWS for holding GB’s of logs, for no reason whatsoever.

So, here’s some C# code (Coded with the help of ChatCPT OpenAI with some modifications), to clear out all your Cloudwatch logs in all regions. You can be less heavy-handed, but I wanted to delete everything.

using Amazon;
using Amazon.CloudWatchLogs;
using Amazon.CloudWatchLogs.Model;
using Amazon.Runtime;

class Program
    static void Main(string[] args)
        const string accessKey = "xxxxxxxxxxxxxxx";
        const string secretKey = "xxxxxxxxxxxxxxx";

        var credentials = new BasicAWSCredentials(accessKey, secretKey);
        foreach (var region in Amazon.RegionEndpoint.EnumerableAllRegions)
            var client = new AmazonCloudWatchLogsClient(credentials, region);
                // Get a list of all log groups
                DescribeLogGroupsResponse logGroupsResponse = null;
                    logGroupsResponse = client.DescribeLogGroupsAsync().Result;
                catch(Exception ex)
                var logGroups = logGroupsResponse.LogGroups;

                // Iterate through each log group and delete it
                foreach (var logGroup in logGroups)
                    // Get a list of all streams in the log group
                    var logStreamsResponse = client.DescribeLogStreamsAsync(new DescribeLogStreamsRequest
                        LogGroupName = logGroup.LogGroupName
                    var logStreams = logStreamsResponse.LogStreams;

                    // Iterate through each stream and delete it
                    foreach (var logStream in logStreams)
                        client.DeleteLogStreamAsync(new DeleteLogStreamRequest
                            LogGroupName = logGroup.LogGroupName,
                            LogStreamName = logStream.LogStreamName
                        Console.WriteLine("Deleted log stream: " + logStream.LogStreamName + " in log group: " + logGroup.LogGroupName);

                    client.DeleteLogGroupAsync(new DeleteLogGroupRequest
                        LogGroupName = logGroup.LogGroupName
                    Console.WriteLine("Deleted log group: " + logGroup.LogGroupName);

                Console.WriteLine("Deleted all log groups and streams in region: " + region.SystemName);
            catch (AmazonCloudWatchLogsException e)
                Console.WriteLine("Error while processing region " + region.SystemName);
                Console.WriteLine("Caught Exception: " + e.Message);
                Console.WriteLine("Response Status Code: " + e.StatusCode);
                Console.WriteLine("Error Code: " + e.ErrorCode);
                Console.WriteLine("Error Type: " + e.ErrorType);
                Console.WriteLine("Request ID: " + e.RequestId);

Hope this helps someone!

Categories: Uncategorized

Comparing #AWS S3 Upload via CLI to #Azure Blob upload via CLI.

The AWS Command Line Interface (CLI) is a unified tool to manage AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

The Azure Command-Line Interface (CLI) is a set of commands used to create and manage Azure resources. It is available on Windows, macOS, and Linux.

Both the AWS CLI and Azure CLI allow you to manage cloud resources from the command line and automate them through scripts. However, there are some key differences to be aware of:

  • Services: AWS offers a wider range of services, but Azure has some services that AWS does not, such as Azure Arc for managing hybrid environments.
  • Language support: The AWS CLI supports multiple programming languages, including Python, Node.js, and C#. The Azure CLI is written in Node.js and is designed to be used with the Azure Resource Manager.
  • Installation and setup: The AWS CLI is installed using a package manager or by downloading a standalone binary. The Azure CLI is installed using a package manager or by downloading the installer.

Overall, both the AWS CLI and Azure CLI are powerful tools that allow you to manage and automate your cloud resources. It really comes down to which cloud platform you are using and which services you need to manage.

Both the AWS and Azure CLI make it easy to upload files, but lets take a look at the difference

To login you type AWS Configure for AWS or AZ login for azure. the AZ login opens a browser so you can provide your credentials, whereas AWS Configure prompts for a IAM user key and secret. In my opinion, AZ makes this process easier for a first time user, but AWS tends to guide you towards the principle of least access better, so more secure for the novice user.

AWS arranges it’s S3 storage into buckets, and optionally folders within the buckets. Azure has storage accounts, and you must have at least one container within the storage account.

To upload a file on Azure it’s

az storage blob upload -f -c database-backups –account-name backupaccount

And the same on AWS is:

aws s3 cp s3://backupaccount/

Some complexities I had found with both Azure and AWS, is if you have multiple accounts, or subscriptions. In Azure, you have to select your subscription as follows;

az account set –subscription “PayAsYouGo”

Wheras, you can have multiple profiles in AWS, and that is selected using

aws s3 cp s3://backupaccount/ –profile AWS

Categories: Uncategorized

U2FsdGVkX1 and #AES – Why you should never use #CryptoJS

If you’re googling the term “U2FsdGVkX1” then you’re looking at some Base64 encoded AES encrypted text? How do I know that, becuase it decodes to “Salted__” – It’s the default value of the first few bytes in a block cypher.

AES (Advanced Encryption Standard) is a symmetric encryption algorithm that is widely used to secure data transmitted over the internet and to store data in encrypted form. One common way to use AES is to encrypt a message with a secret key, which can then be decrypted using the same key.

The “Salted__” prefix that sometimes appears at the beginning of AES-encrypted text is related to a technique called salting, which is used to make it more difficult to attack the encrypted data.

When a message is salted, a random sequence of bits (called a salt) is generated and appended to the message before it is encrypted. The salt is then stored along with the encrypted message, so that it can be used to reconstruct the original message when it is decrypted.

The purpose of salting is to add an extra layer of security to the encryption process by making it more difficult for an attacker to use precomputed tables or other techniques to try to break the encryption. For example, if an attacker knows that a particular message is encrypted with AES, they may be able to use a precomputed table of common words and phrases to try to guess the key and decrypt the message. However, if the message has been salted, the attacker will not be able to use the same precomputed table, because the salt will have changed the encrypted message in a way that is not predictable.

The “Salted__” prefix is added to the beginning of the encrypted message to indicate that the message has been salted, and to provide a place to store the salt. The prefix is followed by the salt itself, which is typically 8 bytes (64 bits) long. The rest of the encrypted message follows the salt.

In summary, the “Salted__” prefix is added to AES-encrypted text to indicate that the message has been salted, and to store the salt used in the salting process. Salting is used to add an extra layer of security to the encryption process by making it more difficult for an attacker to use precomputed tables or other techniques to try to break the encryption.

Beyond the theory, the text U2FsdGVkX1 can indicate the cypher mechanism used, which points an attacker towards AES. AES by itelf is very secure, but implementations of it can be very weak. I would immediately point the finger at CryptoJS. If you are using this in your webpage, you have just added a speedbump to a would-be attacker, nothing more than a paperclip holding your door closed. AES is secure, but it’s symetric, so therefore the client needs to know the key in order to encrypt the data. If you share your key on the page, and your browser can read it, then so can an attacker.

In fact, CryptoJS is such a bad idea, it gives a false sense of security. Is a padlock secure, yes. Is a Padlock with the key left in it still secure? Absolutely not.

Categories: Uncategorized

Poland Vehicle License plate search now available via #API

Today, we have just launched our Vehicle License plate lookup API for poland, available here:

The license plate lookup API for Poland is a tool that enables users to retrieve vehicle information from the Polish vehicle registry by providing the license plate number. This API allows users to access accurate and up-to-date information about vehicles registered in Poland, including details such as the make and model of the vehicle, the year it was manufactured, and the vehicle identification number (VIN).

The license plate lookup API for Poland is easy to use and can be integrated into a wide variety of applications. For example, it can be used by insurance companies to verify the details of a vehicle, or by car rental companies to ensure that the vehicles they are renting out are properly registered. Additionally, the API can be used by law enforcement agencies to quickly and easily obtain information about vehicles that may be involved in a crime.

Overall, the license plate lookup API for Poland is a valuable tool for anyone who needs to access vehicle information in Poland. It is fast, accurate, and easy to use, and can help users save time and improve the accuracy of their vehicle-related operations.

Poland support

Car registration plates in Poland use the /CheckPoland endpoint and return the following information:

  • Make / Model
  • Year
  • VIN
  • Engine Size
  • Power
  • Fuel
  • Weight
  • Region
  • Representative image

Sample Registration Number: 


Sample Json:

  "Description": "SAAB 9-3",
  "RegistrationDate": "2002-06-04",
  "RegistrationYear": 2002,
  "CarMake": {
    "CurrentTextValue": "SAAB"
  "CarModel": {
    "CurrentTextValue": "9-3"
  "MakeDescription": {
    "CurrentTextValue": "SAAB"
  "ModelDescription": {
    "CurrentTextValue": "9-3"
  "VehicleIdentificationNumber": "YS3DD55C622039715",
  "EngineSize": 1985,
  "Power": 110,
  "FuelType": "Petrol",
  "IsPlugIn": "False",
  "SteeringWheelSide": "L",
  "ManufacturingYear": 2002,
  "Mileage": 175102,
  "Weight": "1.9",
  "Region": "Łódź",
  "ImageUrl": ""
Categories: Uncategorized

Running a scheduled task on #AWS – A workaround for the 15 minute #Lambda limit

Let’s start with a bit of context. You want to run a process every day that could last 30 minutes, perhaps you’re importing data from an external source to a database. You can’t use Lambda, because the limit is 15 minutes, and it’s wasteful to use an EC2 instance because for 99% of the time the server will sit idle.

So, containers to the rescue. This is where you firstly write your code, and containerize it. Make sure it runs locally, as expected. Then you push the docker image to ECR. I followed most of the steps in this blog post:

The difference being, in my case, the application had a finite run time – i.e. do a task, then exit (not a web server).

Which means, that after I created my task definition, I then went to the Scheduled Task tab as shown below;

Where I could create a scheduled task that I can set to run every day, or minute, or whatever you need (the minium is 1 minute).

The container will run until it has finished it’s workload, so there is no 15 minute limit, like on AWS lambda.

Categories: Uncategorized
%d bloggers like this: