예제 #1
0
        public static void GenerateRSA(string[] args, Action <string, string> saveAction)
        {
            //Grab the incoming args.
            //Should contain cert name as first arg
            ArgParser appArgs = new ArgParser(args);

            //This will load the cert file with the provided path.
            CertLoader loader = new CertLoader(appArgs.CertName);

            //Once we've loaded the cert we need to pull the RSA data from it.
            //We want to also load it with the private key.
            RSACryptoServiceProvider provider  = new CertToRSAProviderConverter(loader.Certificate, true).Provider;
            RSAExportFormatter       formatter = new RSAExportFormatter(provider);

            try
            {
                saveAction(formatter.ClientRSAXML, $"{appArgs.CertName.Replace(".pfx", "")}Client.rsa");

                saveAction(formatter.ServerRSAXML, $"{appArgs.CertName.Replace(".pfx", "")}Server.rsa");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.ReadKey();
            }
        }
예제 #2
0
		public static void GenerateRSA(string[] args, Action<string, string> saveAction)
		{
			//Grab the incoming args.
			//Should contain cert name as first arg
			ArgParser appArgs = new ArgParser(args);

			//This will load the cert file with the provided path.
			CertLoader loader = new CertLoader(appArgs.CertName);

			//Once we've loaded the cert we need to pull the RSA data from it.
			//We want to also load it with the private key.
			RSACryptoServiceProvider provider = new CertToRSAProviderConverter(loader.Certificate, true).Provider;
			RSAExportFormatter formatter = new RSAExportFormatter(provider);

			try
			{
				saveAction(formatter.ClientRSAXML, $"{appArgs.CertName.Replace(".pfx", "")}Client.rsa");

				saveAction(formatter.ServerRSAXML, $"{appArgs.CertName.Replace(".pfx", "")}Server.rsa");
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				Console.WriteLine(e.StackTrace);
				Console.ReadKey();
			}
		}
예제 #3
0
        public static void Test_Client_And_Server_Dont_Acccidently_Expose_RSA_Parameters()
        {
            //This test was hacked together really quick
            //It's just a security measure to check to make sure exported keys don't leak private key.
            //arrange
            RSAExportFormatter formatter = new RSAExportFormatter(new RSACryptoServiceProvider());

            using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
            {
                //act:
                provider.FromXmlString(formatter.ClientRSAXML);

                //Should be public only
                Assert.IsTrue(provider.PublicOnly);


                //act again
                provider.FromXmlString(formatter.ServerRSAXML);

                //Should be public and private.
                Assert.False(provider.PublicOnly);
            }
        }
		public static void Test_Client_And_Server_Dont_Acccidently_Expose_RSA_Parameters()
		{
			//This test was hacked together really quick
			//It's just a security measure to check to make sure exported keys don't leak private key.
			//arrange
			RSAExportFormatter formatter = new RSAExportFormatter(new RSACryptoServiceProvider());

			using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
			{
				//act:
				provider.FromXmlString(formatter.ClientRSAXML);

				//Should be public only
				Assert.IsTrue(provider.PublicOnly);


				//act again
				provider.FromXmlString(formatter.ServerRSAXML);

				//Should be public and private.
				Assert.False(provider.PublicOnly);
			}
		}