How to Compile Bouncy Castle 1.7 with MS Visual Studio C# Express 2010


I work in the Encryption management space and am in need of some tools to help scale test our product. To that end I am investigating BouncyCastle to see how it can be used in my projects.

After downloading the Bouncy Castle 1.7 source release I had to 'tweak' the project to get it to build. This article describes what I needed to do to get BouncyCastle 1.7 to compile in Visual Studio Expres 2010

 

For a run through on how to create a certificate using bouncy castle, see this BW article.

Notes:

 

After downloading version 1.7 of the source code I had to follow these steps to get it to build in VS 2010 Express:

  • Run through the Conversion Wizard (This pops up automatically)
    BouncyCastleConversionComplete.png
  • Look over the Conversion log error messages that (Complained about IDEA algorithm)
    BouncyCastleConversionReport.png
    • Didn't like:
      • crypto\src\asn1\misc\IDEACBCPar.cs
      • crypto\src\crypto\engines\IDEAEngine.cs
      • crypto\test\src\crypto\test\IDEATest.cs
  • On Closer inspection, it looks like the  files are missing from the project (which is why they can't be converted (They show up as missing when I do a Build -> Build Solution)
    BouncyCastleMissingFileErrors.png

    Error text (for searchability):
    • Error 1 Source file 'C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\src\asn1\misc\IDEACBCPar.cs' could not be opened ('Unspecified error ') crypto
    • Error 2 Source file 'C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\test\src\crypto\test\IDEATest.cs' could not be opened ('Unspecified error ') crypto
    • Error 3 Source file 'C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\src\crypto\engines\IDEAEngine.cs' could not be opened ('Unspecified error ') crypto
    • Error 4 Metadata file 'C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\bin\Debug\crypto.dll' could not be found crypto-test
  • I went through and excluded the missing files from the project (Right-Click -> Exclude From Project):
    BouncyCastleExcludeFromProject.png
  • After removing the files & rebuilding the solution, I see other error messages around IDEA:
    BouncyCastleIdeaErrors.png

    Text for searchability:
    • Error 1 The type or namespace name 'IdeaCbcPar' could not be found (are you missing a using directive or an assembly reference?) C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\test\src\asn1\test\MiscTest.cs 27 9 crypto
    • Error 2 The type or namespace name 'IdeaTest' could not be found (are you missing a using directive or an assembly reference?) C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\test\src\crypto\test\RegressionTest.cs 46 8 crypto
    • Error 3 The type or namespace name 'IdeaEngine' could not be found (are you missing a using directive or an assembly reference?) C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\src\security\MacUtilities.cs 186 38 crypto
    • Error 4 The type or namespace name 'IdeaEngine' could not be found (are you missing a using directive or an assembly reference?) C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\src\security\MacUtilities.cs 190 38 crypto
    • Error 5 The name 'IdeaCbcPar' does not exist in the current context C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\src\security\ParameterUtilities.cs 240 11 crypto
    • Error 6 The type or namespace name 'IdeaCbcPar' could not be found (are you missing a using directive or an assembly reference?) C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\src\security\ParameterUtilities.cs 293 16 crypto
    • Error 7 The type or namespace name 'IdeaEngine' could not be found (are you missing a using directive or an assembly reference?) C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\src\security\CipherUtilities.cs 386 24 crypto
    • Error 8 Metadata file 'C:\Users\rion\Downloads\bccrypto-net-1.7-src\csharp\crypto\bin\Debug\crypto.dll' could not be found crypto-test
  • When I looked at the source code I found that there were a number of these statements scattered throughout:

    #if INCLUDE_IDEA
      // Sourcecode here
    #endif

  • To stop the compiler from taking that code path you need to remove the INCLUDE_IDEA conditional compilation symbol:
    BouncyCastleBuildConditionalSymbols.png

    (In C# Express I had to do Right-Click -> Properties on the Crypto project to get this screen)

 

At this point everything compiled correctly in VS 2010 Express.