Example #1
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();
        }
Example #2
0
        /// <param name="console"></param>
        public static void genRSAKeysText(CryptobyConsole console)
        {
            Scanner scanner = new Scanner(java.lang.System.@in);
            // 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;
                }
            }
            // 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();
            // Print Private Keys
            Console.Out.WriteLine(CryptobyHelper.printPrivateKeyBlock(privateKey));
            // Print Public Keys
            Console.Out.WriteLine(CryptobyHelper.printPublicKeyBlock(publicKey));
            // Enter for Continues
            CryptobyHelper.pressEnter();
            // Back to Menu Choose PrimeTest
            console.menuGenKey();
        }
Example #3
0
        /// <param name="console"></param>
        public static void genSHA3KeyText(CryptobyConsole console)
        {
            Scanner scanner = new Scanner(java.lang.System.@in);
            // Initial Variables
            int    keySize;
            int    choice;
            string pwAns;
            string key;
            string password;

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

            case 2:
            {
                keySize = 256;
                break;
            }

            case 3:
            {
                keySize = 384;
                break;
            }

            case 4:
            {
                keySize = 512;
                break;
            }

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

            default:
            {
                console.menuGenKey();
                break;
            }
            }
            do
            {
                // Input a Password or nothing, in the case it will be used a Secure Random number
                Console.Out.WriteLine("Do you want to use a password. If not, it will be used a SecureRandom password."
                                      );
                Console.Out.Write("Enter y or n: ");
                pwAns = scanner.next();
            }while (!pwAns.Equals("y") && !pwAns.Equals("n"));
            if (pwAns.Equals("y"))
            {
                Console.Out.Write("Enter Password for the Key: ");
                password = scanner.next();
            }
            else
            {
                password = string.Empty;
            }
            // Initial Key Generator
            console.getCore().getClient().setKeySymArt("SHA3");
            console.getCore().initSymKey();
            // Get Result of Test
            if (password.Equals(string.Empty))
            {
                key = console.getCore().getKeyGenSym().generateKey(keySize);
            }
            else
            {
                key = console.getCore().getKeyGenSym().generateKey(keySize, password);
            }
            // Print Key
            Console.Out.WriteLine("SHA3-" + keySize + ": " + key);
            // Enter for Continues
            CryptobyHelper.pressEnter();

            // Back to Menu Choose PrimeTest
            console.menuGenKey();
        }
Example #4
0
        /// <param name="console"></param>
        public static void genSHA3KeyFile(CryptobyConsole console)
        {
            Scanner scanner = new Scanner(java.lang.System.@in);
            string keyPath;
            // Initial Variables
            int keySize;
            int choice;
            string pwAns;
            string key;
            string password;
            // Set Default Key Size
            keySize = 256;
            do
            {
                Console.Out.WriteLine("\n");
                Console.Out.WriteLine("Select Key Size in Bit");
                Console.Out.WriteLine("----------------------\n");
                Console.Out.WriteLine("1 - 224");
                Console.Out.WriteLine("2 - 256");
                Console.Out.WriteLine("3 - 384");
                Console.Out.WriteLine("4 - 512");
                Console.Out.WriteLine("5 - Back");
                Console.Out.Write("Enter Number: ");
                while (!scanner.hasNextInt())
                {
                    Console.Out.WriteLine("That's not a number! Enter 1,2,3,4 or 5:");
                    scanner.next();
                }
                choice = scanner.nextInt();
            }
            while (choice < 1 || choice > 5);
            switch (choice)
            {
                case 1:
                {
                    keySize = 224;
                    break;
                }

                case 2:
                {
                    keySize = 256;
                    break;
                }

                case 3:
                {
                    keySize = 384;
                    break;
                }

                case 4:
                {
                    keySize = 512;
                    break;
                }

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

                default:
                {
                    console.menuGenKey();
                    break;
                }
            }
            do
            {
                // Input a Password or nothing, in the case it will be used a Secure Random number
                Console.Out.WriteLine("Do you want to use a password. If not, it will be used a SecureRandom password."
                    );
                Console.Out.WriteLine("Enter y or n: ");
                pwAns = scanner.next();
            }
            while (!pwAns.Equals("y") && !pwAns.Equals("n"));
            if (pwAns.Equals("y"))
            {
                Console.Out.Write("Enter Password for the Key: ");
                password = scanner.next();
            }
            else
            {
                password = string.Empty;
            }
            // Input Path for saving Private Key
            scanner = new Scanner(java.lang.System.@in);
            Console.Out.WriteLine("Enter Path to saving Private Key(Type '" + quit + "' to Escape):"
                );
            scanner.useDelimiter("\n");
            if (scanner.hasNext(quit))
            {
                console.menuGenKey();
            }
            keyPath = scanner.next();
            // Initial Key Generator
            console.getCore().getClient().setKeySymArt("SHA3");
            console.getCore().initSymKey();
            // Get Result of Test
            if (password.Equals(string.Empty))
            {
                key = console.getCore().getKeyGenSym().generateKey(keySize);
            }
            else
            {
                key = console.getCore().getKeyGenSym().generateKey(keySize, password);
            }
            // Save Key
            try
            {
                //Put private Key to File
                CryptobyFileManager.putKeyToFile(keyPath, key);
            }
            catch (System.IO.IOException)
            {
                CryptobyHelper.printIOExp();
                console.menuGenKey();
            }
            Console.Out.WriteLine("\nAES Key File saved to this Path:");
            Console.Out.WriteLine(keyPath);
            // Enter for Continues
            CryptobyHelper.pressEnter();
            // Back to Menu Choose PrimeTest
            console.menuGenKey();
        }
Example #5
0
        /// <param name="console"></param>
        public static void genRSAKeysText(CryptobyConsole console)
        {
            Scanner scanner = new Scanner(java.lang.System.@in);
            // 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;
            }
            }
            // 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();
            // Print Private Keys
            Console.Out.WriteLine(CryptobyHelper.printPrivateKeyBlock(privateKey));
            // Print Public Keys
            Console.Out.WriteLine(CryptobyHelper.printPublicKeyBlock(publicKey));
            // Enter for Continues
            CryptobyHelper.pressEnter();
            // Back to Menu Choose PrimeTest
            console.menuGenKey();
        }
Example #6
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();
        }