Binary/String conversion using Win32 API

I recently came across the Matasano Crypto Challenges, which is a set of challenges you can go through to learn more about cryptography.

While looking around for tips online for the first challenge, I stumbled upon an excellent blog article by Vadims Podāns, where he shows how, by using the Win32 native functions CryptStringToBinary and CryptBinaryToString, you can easily convert between binary and string in PowerShell.

I built upon his code and created a couple of wrappers around these native functions. This means that I can easily solve the first challenge like this:

$string = '49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'
Invoke-CryptStringToBinary -InputString $string -Format Hex | Invoke-CryptBinaryToString -Format Base64 -NoCrLf

 

I suggest you head over to his blog to see additional examples of these functions in use, or just try them out your self.

 

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s