private static void CreatePgpKeyForAlice(IKeyGenerator keygen) { KeyParameters aliceparam = new KeyParameters { RealName = "Alice", Comment = "my comment", Email = "*****@*****.**", ExpirationDate = DateTime.Now.AddYears(3), KeyLength = KeyParameters.KEY_LENGTH_2048, // primary key parameters PubkeyAlgorithm = KeyAlgorithm.RSA, // the primary key algorithm MUST have the "Sign" capability PubkeyUsage = AlgorithmCapability.CanSign | AlgorithmCapability.CanAuth | AlgorithmCapability.CanCert, // subkey parameters (optional) SubkeyLength = KeyParameters.KEY_LENGTH_4096, SubkeyAlgorithm = KeyAlgorithm.RSA, SubkeyUsage = AlgorithmCapability.CanEncrypt, Passphrase = "topsecret" }; Console.WriteLine( @"Create a new PGP key for Alice. Name: {0} Comment: {1} Email: {2} Secret passphrase: {3} Expire date: {4} Primary key algorithm = {5} ({6} bit) Sub key algorithm = {7} ({8} bit)", aliceparam.RealName, aliceparam.Comment, aliceparam.Email, aliceparam.Passphrase, aliceparam.ExpirationDate.ToString(CultureInfo.InvariantCulture), Gpgme.GetPubkeyAlgoName(aliceparam.PubkeyAlgorithm), aliceparam.PubkeyLength, Gpgme.GetPubkeyAlgoName(aliceparam.SubkeyAlgorithm), aliceparam.SubkeyLength); Console.Write("Start key generation.. "); GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, aliceparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); }
private static void CreatePgpKeyForBob(IKeyGenerator keygen) { Console.Write("Create PGP key for Bob.. "); KeyParameters bobparam = new KeyParameters { RealName = "Bob", Email = "*****@*****.**", ExpirationDate = DateTime.Now.AddYears(2), Passphrase = "topsecret" }; GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, bobparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); }
private static void CreatePgpKeyForMallory(IKeyGenerator keygen) { Console.Write("Create PGP key for Mallory.. "); KeyParameters malloryparam = new KeyParameters { RealName = "Mallory", Email = "*****@*****.**" }; malloryparam.MakeInfinitely(); // PGP key does not expire malloryparam.Passphrase = "topsecret"; GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, malloryparam); Console.WriteLine("done.\nFingerprint: {0}", result.Fingerprint); }
static void Main(string[] args) { Console.WriteLine("This example will create PGP keys in your default keyring.\n"); // First step is to create a context Context ctx = new Context(); EngineInfo info = ctx.EngineInfo; if (info.Protocol != Protocol.OpenPGP) { ctx.SetEngineInfo(Protocol.OpenPGP, null, null); info = ctx.EngineInfo; } Console.WriteLine("GnuPG home directory: {0}\n" + "Version: {1}\n" + "Reqversion: {2} \n" + "Program: {3}\n", info.HomeDir, info.Version, info.ReqVersion, info.FileName); IKeyGenerator keygen = ctx.KeyStore; KeyParameters aliceparam, bobparam, malloryparam; aliceparam = new KeyParameters(); aliceparam.RealName = "Alice"; aliceparam.Comment = "my comment"; aliceparam.Email = "*****@*****.**"; aliceparam.ExpirationDate = DateTime.Now.AddYears(3); // primary key parameters aliceparam.KeyLength = KeyParameters.KEY_LENGTH_2048; aliceparam.PubkeyAlgorithm = KeyAlgorithm.RSA; // the primary key algorithm MUST have the "Sign" capability aliceparam.PubkeyUsage = AlgorithmCapability.CanSign | AlgorithmCapability.CanAuth | AlgorithmCapability.CanCert; // subkey parameters (optional) aliceparam.SubkeyLength = KeyParameters.KEY_LENGTH_4096; aliceparam.SubkeyAlgorithm = KeyAlgorithm.RSA; aliceparam.SubkeyUsage = AlgorithmCapability.CanEncrypt; aliceparam.Passphrase = "topsecret"; // Generate Alice key Console.WriteLine( "Create a new PGP key for Alice.\n" + "Name: {0}\n" + "Comment: {1} \n" + "Email: {2} \n" + "Secret passphrase: {3} \n" + "Expire date: {4} \n" + "Primary key algorithm = {5} ({6} bit)\n" + "Sub key algorithm = {7} ({8} bit)", aliceparam.RealName, aliceparam.Comment, aliceparam.Email, aliceparam.Passphrase, aliceparam.ExpirationDate.ToString(), Gpgme.GetPubkeyAlgoName(aliceparam.PubkeyAlgorithm), aliceparam.PubkeyLength, Gpgme.GetPubkeyAlgoName(aliceparam.SubkeyAlgorithm), aliceparam.SubkeyLength ); Console.Write("Start key generation.. "); GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, aliceparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); // okay, create two more keys Console.Write("Create PGP key for Bob.. "); bobparam = new KeyParameters(); bobparam.RealName = "Bob"; bobparam.Email = "*****@*****.**"; bobparam.ExpirationDate = DateTime.Now.AddYears(2); bobparam.Passphrase = "topsecret"; result = keygen.GenerateKey( Protocol.OpenPGP, bobparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); Console.Write("Create PGP key for Mallory.. "); malloryparam = new KeyParameters(); malloryparam.RealName = "Mallory"; malloryparam.Email = "*****@*****.**"; malloryparam.MakeInfinitely(); // PGP key does not expire malloryparam.Passphrase = "topsecret"; result = keygen.GenerateKey( Protocol.OpenPGP, malloryparam); Console.WriteLine("done.\nFingerprint: {0}", result.Fingerprint); return; }