PowerShell and JSON Web Token Handler

Yesterday, I've been trying to to get Google Admin SDK Directory API (which replaces Google Apps Provisioning API) to work with PowerShell and JSON Web Token (JWT) Handler.

Unfortunately, JWT Handler did not like certificate generated by Google APIs console. I kept receiving the following error:

Exception calling "WriteToken" with "1" argument(s): "Jwt10530: The 'System.IdentityModel.Tokens.X509AsymmetricSecurityKey' for signing cannot be smaller than '2048' bits. Parameter name: key.KeySize Actual value was 1024."

Google APIs console generates a private key of 1024 bits and JWT Handler requires the private key to be at least 2048 bits. The only way I saw to get around this was not to use JWT Handler when connecting to Google's new APIs. (A future post will demonstrate this. Update 2020-03-19, here it is)

If you are working with JWT-enabled web services that support private keys 2048 bits and greater, then you can use the PowerShell code below.

Tested using Windows 8, PowerShell 3.0, .NET Framework 4.5, JSON Web Token Handler For the Microsoft .Net Framework 4.5 1.0, Win32 OpenSSL 1.0.1eNuGet Command-Line Utility 2.7.

  1. Download NuGet Command-Line Utility.
  2. Install the JWT Handler:
    nuget.exe Install System.IdentityModel.Tokens.Jwt
  3. Generate test certificate:
    set OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg

    C:\OpenSSL-Win64\bin\openssl.exe req -x509 -nodes -days 365 -newkey rsa:2048 -keyout D:\myapp.key -out D:\myapp.crt

    C:\OpenSSL-Win64\bin\openssl.exe pkcs12 -export -in D:\myapp.crt -inkey D:\myapp.key -out D:\myapp.pfx

Configure Environment Variables

Note: This post is part of the BCX Getting Started Guide 3.
Updated 2020-03-22.

After you have downloaded and installed Pelles C and BCX, we can configure our system to run BCX or Pelles C in any directory.

To do this, we will bring up the Environment Variables dialog.
  1. Click the Start button.

  2. Type advance, which will search for commands with that text.
  3. Click View advanced system settings.

  4. Click on the Advanced tab.
  5. Click on the Environment Variables button.

  6. Under System variables, click the New button.

  7. For variable name, enter BCX_ROOT.
  8. For variable value, enter C:\Program Files (x86)\BCX.
  9. Click the OK button.

  10. Click on Path.
  11. Click on the Edit button.

  12. Click the New button.
  13. Enter C:\Program Files (x86)\BCX\Bin.

  14. Click the New button.
  15. Enter C:\Program Files\PellesC\Bin.

  16. Click the OK button to close the Environment Variables window.

  17. Click the OK button to close the System Properties window.
If you did not want to modify your environment variables, you can create a batch file and a shortcut that sets the BCX environment for you.
  1. Save the contents of the script below to C:\Program Files (x86)\BCX\Bin\BcxDevCmd.bat.
  2. Right-click your Desktop.
  3. Click on New.
  4. Click on Shortcut.

  5. Click on the Browse button.

  6. Select the batch file C:\Program Files (x86)\BCX\Bin\BcxDevCmd.bat.
  7. Click the OK button.

  8. Click the Next button.

  9. Enter the name BCX SDK Environment. Feel free to call the shortcut something else.
  10. Click the Finish button.

  11. Right-click the newly created shortcut.
  12. Click on Properties.

  13. Add cmd /K in front of the target. This will start a new Command Prompt window and ensure that it does not close until you manually exit the process.
  14. Change the Start in directory to something else. I chose the My Documents folder.
  15. Click the OK button.

  16. Double-click the newly created shortcut to run. You should see a Command Prompt window appear with the title you entered in step 9.

Installing BCX

Note: This post is part of the BCX Getting Started Guide 3.
Updated 2020-03-22.

The official BCX distribution package includes examples for Windows GUI, console, dynamic libraries, complete documentation, the BASIC to C translator, and several utilities including a text editor with syntax highlighting.

To get the latest bleeding-edge BCX tools and help files, visit the BCX Basic Forum. You will need an account to access some files. Registration is free.
  1. Download, extract and run the BCX installer.

  2. Click the Next > button.

  3. Click the Next > button.

  4. Use the default path, click the Next > button.

    Note: The screenshot shows the path C:\Program Files (x86)\BCX. If you are on a 64-bit operating system, this is the default path. On a 32-bit operating system, the path will default to C:\Program Files\BCX.

    Keep note of what path you are using, as further instructions rely on this path.

  5. Install eveything, click the Next > button.

  6. Use the default group name BCX, Click the Next > button.

  7. Create a desktop icon, click the Next > button.

  8. Click the Install button.

    1. If you do not have LCC-Win32 installed, you may get the error below. You can safely ignore this error and click the OK button.

  9. Uncheck Launch BCX - The Free BASIC To C Translator.
  10. Click the Finish button.

  11. Download the BCX 7.4.5 update from the BCX Files Yahoo! Archive. Extract the Bcx745.zip file and save Bc.Exe as C:\Program Files (x86)\BCX\Bin\Bc.Exe.

  12. Download the Bldbat 3.0.0 update from the BCX Files Yahoo! Archive. Extract the Bld Bat . 3.0.0.Zip file and save the files BLDBAT.EXE, BSTART.EXE, FTOOL.EXE to C:\Program Files (x86)\BCX\Bin\.

  13. Login to the BCX Forum, download the BCX Help 7.4.5 update from the Announcements section. Extract the file BCXHelp Version 7.4.5 20200221.zip and save BCXHelp.chm as C:\Program Files (x86)\BCX\Bin\BCXHelp.chm.

  14. Download the Dialog Converter 3.4 update from the BCX GitHub Archive. Save as C:\Program Files (x86)\BCX\Bin\Dc.Exe.

  15. Right-click the file C:\Program Files (x86)\BCX\Bin\Bldbat.Exe.
  16. Click Run as administrator.

    This will ensure you have permission to write to the directory C:\Program Files (x86)\BCX\Bin\.

  17. Click the No button.

  18. Click the No button.

  19. Click the No button.

  20. Click the No button.

  21. Click the No button.

  22. Click the No button.

  23. Select Pelle's C.
  24. Click the Finish button to generate the files BCXCON.BAT, BCXDLL.BAT, BCXGUI.BAT, PC.BAT, PCALL.BAT, PD.BAT, PDALL.BAT, PW.BAT, PWALL.BAT.

Installing Pelles C

Note: This post is part of the BCX Getting Started Guide 3.
Updated 2020-03-22.

Once BCX converts the BCX BASIC source code to C, it will need to be compiled using a C/C++ compiler. For this guide, we will be using the Pelles C development kit.

Pelles C is a complete development kit for Windows. It contains among other things an optimizing C compiler, a macro assembler, a linker, a resource compiler, a message compiler, a make utility and install builder.
  1. Download and run the Pelles C 9.00 setup.

  2. Click I accept the terms in the license agreement.
  3. Click the Next > button.

  4. Click the Next > button.

  5. Select Install for all users on this computer.
  6. Click the Install > button.

  7. Click the Close button.

BCX Getting Started Guide

Note: This post is part of the BCX Getting Started Guide 3.

It has been over 10 years since the BCX Getting Started Guide has been updated. Instead of having to wait another 10 years for a compiled HTML Help version of the documentation, everything will be made available as posts on this website.

There will be a few tweaks here and there, but there are no new example code. Most of the references for compiling the example code will now refer to the Pelles C Compiler, which is the compiler of choice for BCX. Of course other compatible C/C++ compilers can be used as well, such as the Borland C++ Compiler, Microsoft Visual C++, or LCC-Win32.

Once the guide has been completely updated, a compiled HTML Help version will be made available.

Dialog Converter 3.4

While working on the BCX Getting Started Guide 3, I ran into an issue while compiling the example source code for Dialog Converter against Pelles C. When using Dialog Converter with the /l1 expand function names switch, it defines WinMain as int instead of int WINAPI.

Change log:
- Added return type for WinMain when using /l1 option
- Updated build.bat to use Pelles C instead of LCC-Win32
- Added blank afxres.h for vc example


Didn't pay the bills!

Need to restore code from backups someday. Some of the older code may not be restored. BCX code is available here.

Looking for D-Color XP (mentioned on LifeHacker, Shell Extension City, Softpedia, Windows 100%)? It is available at Softpedia.com.