0 votes
by (210 points)

What is process to use Rebex on Mono?

1 Answer

0 votes
by (148k points)

It's the same as using Mono itself - write an application (using C# or another .NET language), compile it and run it. There are IDEs that simplify this process, such as Visual Studio (Windows-only), VS Code or MonoDevelop.

For example, the following application would generate an RSA key and save it's private and public keys to mykey.pri and mykey.pub files:

using System;
using Rebex.Security.Cryptography;
using Rebex.Security.Cryptography.Pkcs;

namespace Rebex.Samples
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Generating RSA private key...");

            // create an instance of AsymmetricKeyAlgorithm
            var alg = new AsymmetricKeyAlgorithm();

            // generate a 2048-bit RSA key pair
            alg.GenerateKey(AsymmetricKeyAlgorithmId.RSA, 2048);

            // retrieve and save the private key in new OpenSSH format
            PrivateKeyInfo privateKey = alg.GetPrivateKey();
            privateKey.Save("mykey.pri", "password", PrivateKeyFormat.NewOpenSsh);

            PublicKeyInfo publicKey = alg.GetPublicKey();
            publicKey.Save("mykey.pub");

            Console.WriteLine("Done.");
        }
    }
}

To use this in .NET or Mono, you first have to compile the application. Mono C# compiler is executed using mcs command, which accepts list of source code files and references:

mcs Program.cs -r:Rebex.Common.dll

Running this would produce Program.exe. To run this on Linux, use mono command:

mono Program.exe

Alternatively, use mkbundle to create a native executable.

...