/// <summary> /// Generate a private/public keypair /// </summary> /// <param name="privatePath">Private Path</param> /// <param name="publicPath">Public Path</param> public static bool GenerateKeypair(String privatePath, String publicPath) { Generate gen = new Generate(); gen.ShowDialog(); if (gen.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return(false); } else { IAsymmetricCipherKeyPairGenerator kpg = new RsaKeyPairGenerator(); kpg.Init(new RsaKeyGenerationParameters(BigInteger.ValueOf(0x13), new SecureRandom(), 1024, 8)); AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair(); FileStream privOut = new FileInfo(privatePath).OpenWrite(); FileStream pubOut = new FileInfo(publicPath).OpenWrite(); Stream privateOut = new ArmoredOutputStream(privOut); Stream publicOut = pubOut; PgpSecretKey privateKey = new PgpSecretKey( PgpSignature.DefaultCertification, PublicKeyAlgorithmTag.RsaGeneral, kp.Public, kp.Private, DateTime.Now, gen.Idendity, SymmetricKeyAlgorithmTag.Cast5, gen.Passphrase.ToCharArray(), null, null, new SecureRandom() ); privateKey.Encode(privateOut); privOut.Close(); publicOut = new ArmoredOutputStream(publicOut); PgpPublicKey key = privateKey.PublicKey; key.Encode(publicOut); pubOut.Close(); // write decrypt comparison PGPLib lib = new PGPLib(File.ReadAllText("key_local/public.key"), File.ReadAllText("key_local/private.key"), gen.Passphrase); File.WriteAllText("key_local/validation.bin", lib.Encrypt("PGPSteam")); return(true); } }
/// <summary> /// Runs the application /// </summary> public void Run() { // ask for passphrase String passphrase = Login.LoginKeypair(); // check valid if (passphrase == null) { Environment.Exit(0); return; } // test decrypt // load pgp stuff m_PGP = new PGPLib(PublicKey, PrivateKey, passphrase); // init steamworks stuff Init(); // open friends window m_FriendsWindow = new Friends(this); // create stuff m_ChatWindows = new Dictionary <CSteamID, PGPSteam.Chat>(); // start callback thread m_CallbackThread = new Thread(new ThreadStart(HandleCallback)); m_CallbackThread.Start(); // run application Application.Run(m_FriendsWindow); // abort callback thread m_CallbackThread.Abort(); }