Example #1
0
        // Asymmetric File Cryption Menu
        public virtual void menuFileAsym()
        {
            int choice;

            do
            {
                Console.Out.WriteLine("\n");
                Console.Out.WriteLine("File Cryption Menu");
                Console.Out.WriteLine("Select Asymmetric Cryption Methode");
                Console.Out.WriteLine("----------------------------------\n");
                Console.Out.WriteLine("1 - RSA");
                Console.Out.WriteLine("2 - Back");
                Console.Out.Write("Enter Number: ");
                while (!scanner.hasNextInt())
                {
                    Console.Out.Write("That's not a number! Enter 1 or 2: ");
                    scanner.next();
                }
                choice = scanner.nextInt();
            }while (choice < 1 || choice > 2);
            switch (choice)
            {
            case 1:
            {
                RsaUI.rsaCrypterFile(this);
                break;
            }

            case 2:
            {
                this.menuFileCrypt();
                break;
            }

            default:
            {
                this.menuFileAsym();
                break;
            }
            }
        }
Example #2
0
        /// <param name="console"></param>
        public static void genRSAKeysFile(CryptobyConsole console)
        {
            Scanner scanner = new Scanner(java.lang.System.@in);
            string  privateKeyPath;
            string  publicKeyPath;
            // Initial Variables
            int    keySize;
            int    choice;
            string publicKey;
            string privateKey;

            // Set Default Key Size
            keySize = 1024;
            do
            {
                Console.Out.WriteLine("\n");
                Console.Out.WriteLine("Choose Key  in Bit");
                Console.Out.WriteLine("-------------------------\n");
                Console.Out.WriteLine("1 - 1024");
                Console.Out.WriteLine("2 - 2048");
                Console.Out.WriteLine("3 - 4096");
                Console.Out.WriteLine("4 - Back");
                Console.Out.Write("Enter Number: ");
                while (!scanner.hasNextInt())
                {
                    Console.Out.WriteLine("That's not a number! Enter 1,2,3 or 4:");
                    scanner.next();
                }
                choice = scanner.nextInt();
            }while (choice < 1 || choice > 4);
            switch (choice)
            {
            case 1:
            {
                keySize = 1024;
                break;
            }

            case 2:
            {
                keySize = 2048;
                break;
            }

            case 3:
            {
                keySize = 4096;
                break;
            }

            case 4:
            {
                console.menuGenKey();
                break;
            }

            default:
            {
                console.menuGenKey();
                break;
            }
            }
            // Input Path for saving Private Key
            Console.Out.WriteLine("Enter Path to saving Private Key (Type '" + quit +
                                  "' to Escape):");
            scanner.useDelimiter("\n");
            if (scanner.hasNext(quit))
            {
                RsaUI.rsaCrypterFile(console);
            }
            privateKeyPath = scanner.next();
            // Input Path for saving Public Key
            Console.Out.WriteLine("Enter Path to saving Public Key (Type '" + quit + "' to Escape):"
                                  );
            scanner.useDelimiter("\n");
            publicKeyPath = scanner.next();
            // Initial Key Generator
            console.getCore().getClient().setKeyAsymArt("RSA");
            console.getCore().initAsymKey();
            // Generate Keys
            console.getCore().getKeyGenAsym().initGenerator(keySize);
            publicKey  = console.getCore().getKeyGenAsym().getPublicKey();
            privateKey = console.getCore().getKeyGenAsym().getPrivateKey();
            //Put private Key to File
            try
            {
                CryptobyFileManager.putKeyToFile(privateKeyPath, privateKey);
            }
            catch (System.IO.IOException)
            {
                CryptobyHelper.printIOExp();
                console.menuGenKey();
            }
            Console.Out.WriteLine("\nPrivate Key File saved to this Path:");
            Console.Out.WriteLine(privateKeyPath);
            //Put public Key to File
            try
            {
                CryptobyFileManager.putKeyToFile(publicKeyPath, publicKey);
            }
            catch (System.IO.IOException)
            {
                CryptobyHelper.printIOExp();
                console.menuGenKey();
            }
            Console.Out.WriteLine("\nPublic Key File saved to this Path:");
            Console.Out.WriteLine(publicKeyPath);
            // Enter for Continues
            CryptobyHelper.pressEnter();
            // Back to Menu Choose PrimeTest
            console.menuGenKey();
        }