Пример #1
0
        /// <param name="console"></param>
        public static void aesCrypterFile(CryptobyConsole console)
        {
            Console.Out.WriteLine("\n");
            Console.Out.WriteLine("AES File Crypter");
            Console.Out.WriteLine("----------------\n");
            switch (choiceText())
            {
            case 1:
            {
                aesEncrypterFile(console);
                break;
            }

            case 2:
            {
                aesDecrypterFile(console);
                break;
            }

            case 3:
            {
                console.menuFileSym();
                break;
            }

            default:
            {
                aesCrypterFile(console);
                break;
            }
            }
        }
Пример #2
0
 private static byte[] scanKeyFile(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     byte[] tempKey = null;
     do
     {
         Console.Out.WriteLine("\nAllowed Key Sizes 128,192 and 256 Bit.");
         Console.Out.WriteLine("Enter Path to Key File (Type '" + quit + "' to Escape):"
                               );
         if (scanner.hasNext(quit))
         {
             aesCrypterFile(console);
         }
         keyPath = scanner.next();
         try
         {
             tempKey = CryptobyFileManager.getKeyFromFile(keyPath);
         }
         catch (System.IO.IOException)
         {
             CryptobyHelper.printIOExp();
             aesCrypterFile(console);
         }
         catch (FormatException)
         {
             Console.Out.WriteLine("Key File format is not correct!");
             aesCrypterFile(console);
         }
         keySize = tempKey.Length * 4;
     }while (keySize != 128 && keySize != 192 && keySize != 256);
     return(tempKey);
 }
Пример #3
0
        /// <param name="console"></param>
        public static void aesCrypterFile(CryptobyConsole console)
        {
            Console.Out.WriteLine("\n");
            Console.Out.WriteLine("AES File Crypter");
            Console.Out.WriteLine("----------------\n");
            switch (choiceText())
            {
                case 1:
                {
                    aesEncrypterFile(console);
                    break;
                }

                case 2:
                {
                    aesDecrypterFile(console);
                    break;
                }

                case 3:
                {
                    console.menuFileSym();
                    break;
                }

                default:
                {
                    aesCrypterFile(console);
                    break;
                }
            }
        }
Пример #4
0
 private static void aesEncrypterText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     scanner.useDelimiter("\n");
     // Input your String Text to encrypt
     Console.Out.WriteLine("\nYour Text to encrypt (Type '" + quit + "' to Escape):"
                           );
     if (scanner.hasNext(quit))
     {
         aesCrypterText(console);
     }
     plainByte = Encoding.UTF8.GetBytes(scanner.next());
     // Input your Key for encryption
     key = scanKeyText(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Encrypt the String Text with given Key
     Console.Out.WriteLine("\nEncrypting in progress...");
     cryptByte = console.getCore().getCryptSym().encrypt(plainByte, key);
     // Convert byte Array into a Hexcode String
     charTextHex = CryptobyHelper.bytesToHexStringUpper(cryptByte).ToCharArray();
     // Print encrypted Text in Hex Block form
     Console.Out.WriteLine("\nEncryption successfull...");
     Console.Out.WriteLine(CryptobyHelper.printHexBlock("AES", keySize, charTextHex
                                                        ));
     // Back to Text Crypter Menu
     Console.Out.WriteLine("\nGo back to AES Text Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterText(console);
 }
Пример #5
0
 private static void rsaDecrypterText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     // Input encrypted Hex String Text to decrypt
     Console.Out.WriteLine("\nYour Text to decrypt (Type '" + quit + "' to Escape):"
                           );
     // Convert crypted HexString Block to one String
     try
     {
         string cryptText = string.Empty;
         while (!scanner.hasNext(CryptobyHelper.getEOBString()))
         {
             if (scanner.hasNext(quit))
             {
                 rsaCrypterText(console);
             }
             cryptText = cryptText + scanner.next();
         }
         cryptByte = CryptobyHelper.hexStringToBytes(cryptText);
     }
     catch (FormatException)
     {
         // Catch false format of Input
         Console.Out.WriteLine("\nNot allowed Crypted Text! Must be a Upper Hex String!"
                               );
         cryptByte = BigInteger.ZERO.toByteArray();
     }
     // Input the Private Key
     privateKeyByte = scanPrivateKey(console);
     // Initial RSA Crypt Object
     initRSAKeyGen(console);
     // Decrypt the String Text with given Key
     Console.Out.WriteLine("\nDecryption in progress...");
     try
     {
         plainByte = console.getCore().getCryptAsym().decrypt(cryptByte, privateKeyByte);
     }
     catch (Exception)
     {
         Console.Out.WriteLine("\nUnable to decrypt this String!!");
         plainByte = null;
         // Press Return for Continues
         CryptobyHelper.pressEnter();
         rsaCrypterText(console);
     }
     Console.Out.WriteLine("\nDecryption finished...");
     // Print decrypted Text
     Console.Out.WriteLine("\nRSA-" + keySize + " decrypted Text:");
     Console.Out.WriteLine(Encoding.UTF8.GetString(plainByte));
     // Reset RSA Crypt Object to release Memory
     initRSAKeyGen(console);
     // Back to Menu rsaCrypter with Enter (Return) Key
     Console.Out.WriteLine("\nGo back to RSA Text Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     rsaCrypterText(console);
 }
Пример #6
0
 private static byte[] scanPlainText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Your Text to encrypt (Type '" + quit + "' to Escape):"
                           );
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         rsaCrypterText(console);
     }
     return(Encoding.UTF8.GetBytes(scanner.next()));
 }
Пример #7
0
 private static void aesDecrypterText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     // Input encrypted Hex String Text to decrypt
     Console.Out.WriteLine("\nYour Text to decrypt (Type '" + quit + "' to Escape):"
                           );
     // Convert crypted HexString Block to one String
     try
     {
         string cryptText = string.Empty;
         while (!scanner.hasNext(CryptobyHelper.getEOBString()))
         {
             if (scanner.hasNext(quit))
             {
                 aesCrypterText(console);
             }
             cryptText = cryptText + scanner.next();
         }
         cryptByte = CryptobyHelper.hexStringToBytes(cryptText);
     }
     catch (FormatException)
     {
         // Catch false format of Input
         Console.Out.WriteLine("\nNot allowed Crypted Text! Must be a Upper Hex String!"
                               );
         cryptByte = BigInteger.ZERO.toByteArray();
     }
     // Input your Key for encryption
     key = scanKeyText(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Decrypt the String Text with given Key
     Console.Out.WriteLine("\nDecrypting in progress...");
     try
     {
         plainByte = console.getCore().getCryptSym().decrypt(cryptByte, key);
     }
     catch (Exception)
     {
         Console.Out.WriteLine("\nUnable to decrypt this String!!");
         // Enter for Continues
         CryptobyHelper.pressEnter();
         aesCrypterText(console);
     }
     // Print decrypted Text
     Console.Out.WriteLine("\nDecryption finished...");
     Console.Out.WriteLine("\nAES-" + keySize + " decrypted Text:");
     Console.Out.WriteLine(Encoding.UTF8.GetString(plainByte));
     // Back to Text Crypter Menu
     Console.Out.WriteLine("\nGo back to AES Text Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterText(console);
 }
Пример #8
0
 /// <param name="console"></param>
 public static void testMillerRabin(CryptobyConsole console)
 {
     Scanner scanner = new Scanner(java.lang.System.@in);
     // Initial Variables
     int rounds;
     string percent;
     BigInteger number;
     do
     {
         // Input Number for Primenumber Testing
         System.Console.Out.WriteLine("Set Primenumber to Test.");
         System.Console.Out.Write("Please enter a positive number: ");
         while (!scanner.hasNextBigInteger())
         {
             System.Console.Out.Write("That's not a number! Enter a positive number: ");
             scanner.next();
         }
         number = scanner.nextBigInteger();
     }
     while (number.compareTo(BigInteger.ONE) < 0);
     do
     {
         // Set the rounds of the Miller Rabin Test
         System.Console.Out.WriteLine("Set rounds parameter between 1 and 15.");
         System.Console.Out.Write("Please enter the number of rounds: ");
         while (!scanner.hasNextInt())
         {
             System.Console.Out.Write("That's not a number! Enter a valid number: ");
             scanner.next();
         }
         rounds = scanner.nextInt();
     }
     while (rounds < 1 || rounds > 15);
     // Initial Miller Rabin Object
     console.getCore().getClient().setPrimTestArt("MillerRabin");
     console.getCore().getClient().setPrimetestrounds(rounds);
     console.getCore().initPrimeTest();
     // Get Result of Test
     if (console.getCore().getPrimetest().isPrime(number))
     {
         percent = console.getCore().getPrimetest().getProbability().ToString();
         System.Console.Out.WriteLine("\nResult: Number is probably a Primenumber, probability: "
              + percent + "%");
     }
     else
     {
         System.Console.Out.WriteLine("\nResult: Number is NOT a Primenumber");
     }
     // Back to Menu Choose PrimeTest
     System.Console.Out.WriteLine("\nGo back to Primetest Menu: Press Enter");
     CryptobyHelper.pressEnter();
     console.menuPrimeTest();
 }
Пример #9
0
        // UIs for Text Cryption Menu
        /// <param name="console"></param>
        public static void rsaCrypterText(CryptobyConsole console)
        {
            scanner = new Scanner(java.lang.System.@in);
            do
            {
                Console.Out.WriteLine("\n");
                Console.Out.WriteLine("RSA Text Cryption");
                Console.Out.WriteLine("-----------------\n");
                Console.Out.WriteLine("1 - Encryption and generate Keys");
                Console.Out.WriteLine("2 - Encryption with own Key");
                Console.Out.WriteLine("3 - Decryption");
                Console.Out.WriteLine("4 - Back");
                Console.Out.Write("Enter Number: ");
                while (!scanner.hasNextInt())
                {
                    Console.Out.Write("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:
            {
                rsaEncGenKeysText(console);
                break;
            }

            case 2:
            {
                rsaEncrypterText(console);
                break;
            }

            case 3:
            {
                rsaDecrypterText(console);
                break;
            }

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

            default:
            {
                rsaCrypterText(console);
                break;
            }
            }
        }
Пример #10
0
        /// <param name="console"></param>
        public static void testMillerRabin(CryptobyConsole console)
        {
            Scanner scanner = new Scanner(java.lang.System.@in);
            // Initial Variables
            int        rounds;
            string     percent;
            BigInteger number;

            do
            {
                // Input Number for Primenumber Testing
                System.Console.Out.WriteLine("Set Primenumber to Test.");
                System.Console.Out.Write("Please enter a positive number: ");
                while (!scanner.hasNextBigInteger())
                {
                    System.Console.Out.Write("That's not a number! Enter a positive number: ");
                    scanner.next();
                }
                number = scanner.nextBigInteger();
            }while (number.compareTo(BigInteger.ONE) < 0);
            do
            {
                // Set the rounds of the Miller Rabin Test
                System.Console.Out.WriteLine("Set rounds parameter between 1 and 15.");
                System.Console.Out.Write("Please enter the number of rounds: ");
                while (!scanner.hasNextInt())
                {
                    System.Console.Out.Write("That's not a number! Enter a valid number: ");
                    scanner.next();
                }
                rounds = scanner.nextInt();
            }while (rounds < 1 || rounds > 15);
            // Initial Miller Rabin Object
            console.getCore().getClient().setPrimTestArt("MillerRabin");
            console.getCore().getClient().setPrimetestrounds(rounds);
            console.getCore().initPrimeTest();
            // Get Result of Test
            if (console.getCore().getPrimetest().isPrime(number))
            {
                percent = console.getCore().getPrimetest().getProbability().ToString();
                System.Console.Out.WriteLine("\nResult: Number is probably a Primenumber, probability: "
                                             + percent + "%");
            }
            else
            {
                System.Console.Out.WriteLine("\nResult: Number is NOT a Primenumber");
            }
            // Back to Menu Choose PrimeTest
            System.Console.Out.WriteLine("\nGo back to Primetest Menu: Press Enter");
            CryptobyHelper.pressEnter();
            console.menuPrimeTest();
        }
Пример #11
0
 // Helper Functions
 private static byte[] scanKeyText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     byte[] tempKey;
     do
     {
         Console.Out.WriteLine("\nAllowed Key Sizes 128,192 and 256 Bit.");
         Console.Out.WriteLine("Enter the AES Key (Type '" + quit + "' to Escape):"
                               );
         if (scanner.hasNext(quit))
         {
             aesCrypterText(console);
         }
         tempKey = Encoding.UTF8.GetBytes(scanner.next());
         keySize = tempKey.Length * 4;
     }while (keySize != 128 && keySize != 192 && keySize != 256);
     return(tempKey);
 }
Пример #12
0
 // Help Functions
 private static byte[] scanPrivateKey(CryptobyConsole console)
 {
     byte[] retKey = null;
     do
     {
         scanner = new Scanner(java.lang.System.@in);
         string keyText = string.Empty;
         // Input Private Key for decryption
         Console.Out.WriteLine("\nEnter the private Key (Type '" + quit + "' to Escape):"
                               );
         try
         {
             while (!scanner.hasNext(CryptobyHelper.getEOBString()))
             {
                 if (scanner.hasNext(quit))
                 {
                     rsaCrypterText(console);
                 }
                 keyText = keyText + scanner.next();
             }
             retKey  = CryptobyHelper.hexStringToBytes(keyText);
             keySize = retKey.Length * 4;
         }
         catch (FormatException)
         {
             // Catch false format of Input
             Console.Out.WriteLine("Not allowed Characters in Private Key! Just lower alphanumeric Characters!"
                                   );
             retKey  = BigInteger.ZERO.toByteArray();
             keySize = 0;
         }
         catch (ArgumentNullException)
         {
             Console.Out.WriteLine("NullPointerException catched! Try again!");
             retKey  = BigInteger.ZERO.toByteArray();
             keySize = 0;
         }
     }while (keySize != 1024 && keySize != 2048 && keySize != 4096);
     return(retKey);
 }
Пример #13
0
 private static void rsaEncrypterText(CryptobyConsole console)
 {
     // Input your String Text to encrypt
     plainByte = scanPlainText(console);
     // Input the Public Key to encrypt
     publicKeyByte = scanPublicKey(console);
     // Initial RSA Crypt Object
     initRSAKeyGen(console);
     // Encrypt the String Text with given Key
     Console.Out.WriteLine("\nEncryption in progress...");
     cryptByte = console.getCore().getCryptAsym().encrypt(plainByte, publicKeyByte);
     Console.Out.WriteLine("\nEncryption successfull...");
     // Convert byte Array into a Hexcode String
     charTextHex = CryptobyHelper.bytesToHexStringUpper(cryptByte).ToCharArray();
     // Print encrypted Text in Hex Block form
     Console.Out.WriteLine(CryptobyHelper.printHexBlock("RSA", keySize, charTextHex
                                                        ));
     // Back to Menu rsaCrypter with Enter (Return) Key
     Console.Out.WriteLine("\nGo back to RSA Text Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     rsaCrypterText(console);
 }
Пример #14
0
 private static void aesDecrypterText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     // Input encrypted Hex String Text to decrypt
     Console.Out.WriteLine("\nYour Text to decrypt (Type '" + quit + "' to Escape):"
         );
     // Convert crypted HexString Block to one String
     try
     {
         string cryptText = string.Empty;
         while (!scanner.hasNext(CryptobyHelper.getEOBString()))
         {
             if (scanner.hasNext(quit))
             {
                 aesCrypterText(console);
             }
             cryptText = cryptText + scanner.next();
         }
         cryptByte = CryptobyHelper.hexStringToBytes(cryptText);
     }
     catch (FormatException)
     {
         // Catch false format of Input
         Console.Out.WriteLine("\nNot allowed Crypted Text! Must be a Upper Hex String!"
             );
         cryptByte = BigInteger.ZERO.toByteArray();
     }
     // Input your Key for encryption
     key = scanKeyText(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Decrypt the String Text with given Key
     Console.Out.WriteLine("\nDecrypting in progress...");
     try
     {
         plainByte = console.getCore().getCryptSym().decrypt(cryptByte, key);
     }
     catch (Exception)
     {
         Console.Out.WriteLine("\nUnable to decrypt this String!!");
         // Enter for Continues
         CryptobyHelper.pressEnter();
         aesCrypterText(console);
     }
     // Print decrypted Text
     Console.Out.WriteLine("\nDecryption finished...");
     Console.Out.WriteLine("\nAES-" + keySize + " decrypted Text:");
     Console.Out.WriteLine(Encoding.UTF8.GetString(plainByte));
     // Back to Text Crypter Menu
     Console.Out.WriteLine("\nGo back to AES Text Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterText(console);
 }
Пример #15
0
 private static void aesEncrypterText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     scanner.useDelimiter("\n");
     // Input your String Text to encrypt
     Console.Out.WriteLine("\nYour Text to encrypt (Type '" + quit + "' to Escape):"
         );
     if (scanner.hasNext(quit))
     {
         aesCrypterText(console);
     }
     plainByte = Encoding.UTF8.GetBytes(scanner.next());
     // Input your Key for encryption
     key = scanKeyText(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Encrypt the String Text with given Key
     Console.Out.WriteLine("\nEncrypting in progress...");
     cryptByte = console.getCore().getCryptSym().encrypt(plainByte, key);
     // Convert byte Array into a Hexcode String
     charTextHex = CryptobyHelper.bytesToHexStringUpper(cryptByte).ToCharArray();
     // Print encrypted Text in Hex Block form
     Console.Out.WriteLine("\nEncryption successfull...");
     Console.Out.WriteLine(CryptobyHelper.printHexBlock("AES", keySize, charTextHex
         ));
     // Back to Text Crypter Menu
     Console.Out.WriteLine("\nGo back to AES Text Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterText(console);
 }
Пример #16
0
 private static void aesEncrypterFile(CryptobyConsole console)
 {
     // Input Path to File for encryption
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to File for encryption (Type '" + quit +
          "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     plainFilePath = scanner.next();
     // Get Bytes from PlainFile
     try
     {
         plainByte = CryptobyFileManager.getBytesFromFile(plainFilePath);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         aesCrypterFile(console);
     }
     // Input Path saving Path
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to save encrypted File (Type '" + quit +
          "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     cryptFilePath = scanner.next();
     // Input Key File for encryption
     key = scanKeyFile(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Encrypt the String Text with given Key
     Console.Out.WriteLine("\nEncrypting in progress...");
     cryptByte = console.getCore().getCryptSym().encrypt(plainByte, key);
     Console.Out.WriteLine("\nEncryption successfull. Saving File now...");
     //Put encrypted Bytes to File
     try
     {
         CryptobyFileManager.putBytesToFile(cryptFilePath, cryptByte);
     }
     catch (System.IO.IOException ex)
     {
         Logger.getLogger(typeof(RsaUI).FullName).log(Level.SEVERE, null, ex);
     }
     Console.Out.WriteLine("\nEncrypted File saved to this Path:");
     Console.Out.WriteLine(cryptFilePath);
     // Reset Variables
     initAESKeyGen(console);
     cryptByte = null;
     plainByte = null;
     key = null;
     // Back to File Crypter Menu
     Console.Out.WriteLine("\nGo back to AES File Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterFile(console);
 }
Пример #17
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();
        }
Пример #18
0
 private static void aesDecrypterFile(CryptobyConsole console)
 {
     // Input Path to File for decryption
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to decrypt a File (Type '" + quit + "' to Escape):"
                           );
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     cryptFilePath = scanner.next();
     try
     {
         // Get Bytes from PlainFile
         cryptByte = CryptobyFileManager.getBytesFromFile(cryptFilePath);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         aesCrypterFile(console);
     }
     // Input Path saving Path
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to save decrypted File (Type '" + quit +
                           "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     plainFilePath = scanner.next();
     // Input your Key for encryption
     key = scanKeyFile(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Decrypt the String Text with given Key
     Console.Out.WriteLine("\nDecrypting in progress...");
     try
     {
         plainByte = console.getCore().getCryptSym().decrypt(cryptByte, key);
     }
     catch (Exception)
     {
         Console.Out.WriteLine("\nUnable to decrypt this String!!");
         // Enter for Continues
         CryptobyHelper.pressEnter();
         aesCrypterFile(console);
     }
     Console.Out.WriteLine("\nDecryption finished. Saving File now...");
     try
     {
         //Put encrypted Bytes to File
         CryptobyFileManager.putBytesToFile(plainFilePath, plainByte);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         aesCrypterFile(console);
     }
     Console.Out.WriteLine("\nDecrypted File saved to this Path:");
     Console.Out.WriteLine(plainFilePath);
     // Reset Variables
     initAESKeyGen(console);
     cryptByte = null;
     plainByte = null;
     key       = null;
     // Back to File Crypter Menu
     Console.Out.WriteLine("\nGo back to AES File Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterFile(console);
 }
Пример #19
0
 private static void rsaDecrypterFile(CryptobyConsole console)
 {
     // Input Path to File for decryption
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to File for Decryption (Type '" + quit +
                           "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         rsaCrypterFile(console);
     }
     cryptFilePath = scanner.next();
     // Get Bytes from PlainFile
     try
     {
         cryptByte = CryptobyFileManager.getBytesFromFile(cryptFilePath);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         rsaCrypterFile(console);
     }
     // Input Path saving Path
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter saving Path for decrypted File (Type '" + quit
                           + "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         rsaCrypterFile(console);
     }
     plainFilePath = scanner.next();
     // Input Path to Key File for decryption
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to Private Key File (Type '" + quit + "' to Escape):"
                           );
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         rsaCrypterFile(console);
     }
     privateKeyPath = scanner.next();
     // Get Bytes from Private Key File
     try
     {
         privateKeyByte = CryptobyFileManager.getKeyFromFile(privateKeyPath);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         rsaCrypterFile(console);
     }
     catch (FormatException)
     {
         Console.Out.WriteLine("Key File format is not correct!");
         rsaCrypterFile(console);
     }
     // Initial RSA Crypt Object
     initRSAKeyGen(console);
     // Encrypt the File with given Key
     Console.Out.WriteLine("\nDecryption in progress...");
     try
     {
         plainByte = console.getCore().getCryptAsym().decrypt(cryptByte, privateKeyByte);
     }
     catch (Exception)
     {
         Console.Out.WriteLine("\nUnable to decrypt this File!!");
         plainByte = null;
         // Press Return for Continues
         CryptobyHelper.pressEnter();
         rsaCrypterFile(console);
     }
     Console.Out.WriteLine("\nDecryption finished. Saving File now...");
     try
     {
         //Put encrypted Bytes to File
         CryptobyFileManager.putBytesToFile(plainFilePath, plainByte);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         rsaCrypterFile(console);
     }
     Console.Out.WriteLine("\nDecrypted File saved to this Path:");
     Console.Out.WriteLine(plainFilePath);
     // Reset Variables
     initRSAKeyGen(console);
     cryptByte     = null;
     plainByte     = null;
     publicKeyByte = null;
     // Back to Menu rsaCrypter with Enter (Return) Key
     Console.Out.WriteLine("\nGo back to RSA File Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     rsaCrypterFile(console);
 }
Пример #20
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();
        }
Пример #21
0
 private static void initAESKeyGen(CryptobyConsole console)
 {
     console.getCore().getClient().setCryptSymArt("AES");
     console.getCore().initCryptSym();
 }
Пример #22
0
 private static void initRSAKeyGen(CryptobyConsole console)
 {
     console.getCore().getClient().setCryptAsymArt("RSA");
     console.getCore().initCryptAsym();
 }
Пример #23
0
 // Helper Functions
 private static byte[] scanKeyText(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     byte[] tempKey;
     do
     {
         Console.Out.WriteLine("\nAllowed Key Sizes 128,192 and 256 Bit.");
         Console.Out.WriteLine("Enter the AES Key (Type '" + quit + "' to Escape):"
             );
         if (scanner.hasNext(quit))
         {
             aesCrypterText(console);
         }
         tempKey = Encoding.UTF8.GetBytes(scanner.next());
         keySize = tempKey.Length * 4;
     }
     while (keySize != 128 && keySize != 192 && keySize != 256);
     return tempKey;
 }
Пример #24
0
 private static byte[] scanKeyFile(CryptobyConsole console)
 {
     scanner = new Scanner(java.lang.System.@in);
     byte[] tempKey = null;
     do
     {
         Console.Out.WriteLine("\nAllowed Key Sizes 128,192 and 256 Bit.");
         Console.Out.WriteLine("Enter Path to Key File (Type '" + quit + "' to Escape):"
             );
         if (scanner.hasNext(quit))
         {
             aesCrypterFile(console);
         }
         keyPath = scanner.next();
         try
         {
             tempKey = CryptobyFileManager.getKeyFromFile(keyPath);
         }
         catch (System.IO.IOException)
         {
             CryptobyHelper.printIOExp();
             aesCrypterFile(console);
         }
         catch (FormatException)
         {
             Console.Out.WriteLine("Key File format is not correct!");
             aesCrypterFile(console);
         }
         keySize = tempKey.Length * 4;
     }
     while (keySize != 128 && keySize != 192 && keySize != 256);
     return tempKey;
 }
Пример #25
0
        private static void rsaEncGenKeysText(CryptobyConsole console)
        {
            scanner = new Scanner(java.lang.System.@in);
            string privateKey;
            string publicKey;

            // Set Default Key Size
            keySize = 1024;
            do
            {
                Console.Out.WriteLine("\n");
                Console.Out.WriteLine("Choose Key Size 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.Write("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:
            {
                rsaCrypterText(console);
                break;
            }

            default:
            {
                rsaEncGenKeysText(console);
                break;
            }
            }
            // Input your String Text to encrypt
            plainByte = scanPlainText(console);
            // Initial RSA Crypt Object
            initRSAKeyGen(console);
            // Get Public Key in Bytecode
            Console.Out.WriteLine("\nGenerate Private and Public RSA Keys...");
            console.getCore().getKeyGenAsym().initGenerator(keySize);
            publicKeyByte = console.getCore().getKeyGenAsym().getPublicKeyByte();
            // Get Public and Private Key as String
            publicKey  = console.getCore().getKeyGenAsym().getPublicKey();
            privateKey = console.getCore().getKeyGenAsym().getPrivateKey();
            // Encrypt the String Text with given Key
            Console.Out.WriteLine("\nEncryption in progress...");
            cryptByte = console.getCore().getCryptAsym().encrypt(plainByte, publicKeyByte);
            Console.Out.WriteLine("\nEncryption successfull...");
            // Convert crypted byte Array into a Hexcode String
            charTextHex = CryptobyHelper.bytesToHexStringUpper(cryptByte).ToCharArray();
            // Print encrypted Text in Hex Block form
            Console.Out.WriteLine(CryptobyHelper.printHexBlock("RSA", keySize, charTextHex
                                                               ));
            // Print Private Keys
            Console.Out.WriteLine(CryptobyHelper.printPrivateKeyBlock(privateKey));
            // Print Public Keys
            Console.Out.WriteLine(CryptobyHelper.printPublicKeyBlock(publicKey));
            // Back to Menu rsaCrypter with Enter (Return) Key
            Console.Out.WriteLine("\nGo back to RSA Text Crypter Menu: Press Enter");
            CryptobyHelper.pressEnter();
            rsaCrypterText(console);
        }
Пример #26
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();
        }
Пример #27
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();
        }
Пример #28
0
 private static void aesDecrypterFile(CryptobyConsole console)
 {
     // Input Path to File for decryption
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to decrypt a File (Type '" + quit + "' to Escape):"
         );
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     cryptFilePath = scanner.next();
     try
     {
         // Get Bytes from PlainFile
         cryptByte = CryptobyFileManager.getBytesFromFile(cryptFilePath);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         aesCrypterFile(console);
     }
     // Input Path saving Path
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to save decrypted File (Type '" + quit +
          "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     plainFilePath = scanner.next();
     // Input your Key for encryption
     key = scanKeyFile(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Decrypt the String Text with given Key
     Console.Out.WriteLine("\nDecrypting in progress...");
     try
     {
         plainByte = console.getCore().getCryptSym().decrypt(cryptByte, key);
     }
     catch (Exception)
     {
         Console.Out.WriteLine("\nUnable to decrypt this String!!");
         // Enter for Continues
         CryptobyHelper.pressEnter();
         aesCrypterFile(console);
     }
     Console.Out.WriteLine("\nDecryption finished. Saving File now...");
     try
     {
         //Put encrypted Bytes to File
         CryptobyFileManager.putBytesToFile(plainFilePath, plainByte);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         aesCrypterFile(console);
     }
     Console.Out.WriteLine("\nDecrypted File saved to this Path:");
     Console.Out.WriteLine(plainFilePath);
     // Reset Variables
     initAESKeyGen(console);
     cryptByte = null;
     plainByte = null;
     key = null;
     // Back to File Crypter Menu
     Console.Out.WriteLine("\nGo back to AES File Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterFile(console);
 }
Пример #29
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();
        }
Пример #30
0
 private static void initAESKeyGen(CryptobyConsole console)
 {
     console.getCore().getClient().setCryptSymArt("AES");
     console.getCore().initCryptSym();
 }
Пример #31
0
        private static void rsaEncGenKeysFile(CryptobyConsole console)
        {
            scanner = new Scanner(java.lang.System.@in);
            // Set Default Key Size
            keySize = 1024;
            do
            {
                Console.Out.WriteLine("\n");
                Console.Out.WriteLine("Choose Key Size 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.Write("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:
            {
                rsaCrypterFile(console);
                break;
            }

            default:
            {
                rsaEncGenKeysFile(console);
                break;
            }
            }
            // Input Path to File for encryption
            scanner = new Scanner(java.lang.System.@in);
            Console.Out.WriteLine("Enter Path to File for encryption (Type '" + quit +
                                  "' to Escape):");
            scanner.useDelimiter("\n");
            if (scanner.hasNext(quit))
            {
                rsaCrypterFile(console);
            }
            plainFilePath = scanner.next();
            // Input Path to File for encryption
            scanner = new Scanner(java.lang.System.@in);
            Console.Out.WriteLine("Enter Path to saving encrypted File (Type '" + quit
                                  + "' to Escape):");
            scanner.useDelimiter("\n");
            if (scanner.hasNext(quit))
            {
                rsaCrypterFile(console);
            }
            cryptFilePath = scanner.next();
            // 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))
            {
                rsaCrypterFile(console);
            }
            privateKeyPath = scanner.next();
            // Input Path for saving Public Key
            scanner = new Scanner(java.lang.System.@in);
            Console.Out.WriteLine("Enter Path to saving Public Key (Type '" + quit + "' to Escape):"
                                  );
            scanner.useDelimiter("\n");
            publicKeyPath = scanner.next();
            // Get Bytes from PlainFile
            try
            {
                plainByte = CryptobyFileManager.getBytesFromFile(plainFilePath);
            }
            catch (System.IO.IOException)
            {
                CryptobyHelper.printIOExp();
                rsaCrypterFile(console);
            }
            // Initial RSA Crypt Object
            initRSAKeyGen(console);
            // Get Public Key in Bytecode
            Console.Out.WriteLine("\nGenerate Private and Public RSA Keys...");
            console.getCore().getKeyGenAsym().initGenerator(keySize);
            publicKeyByte = console.getCore().getKeyGenAsym().getPublicKeyByte();
            // Get Public and Private Key as String
            string publicKey  = console.getCore().getKeyGenAsym().getPublicKey();
            string privateKey = console.getCore().getKeyGenAsym().getPrivateKey();

            // Encrypt the File with given Key
            Console.Out.WriteLine("\nEncryption in progress...");
            cryptByte = console.getCore().getCryptAsym().encrypt(plainByte, publicKeyByte);
            Console.Out.WriteLine("\nEncryption successfull. Saving File now...");
            //Put encrypted Bytes to File
            try
            {
                CryptobyFileManager.putBytesToFile(cryptFilePath, cryptByte);
            }
            catch (System.IO.IOException)
            {
                CryptobyHelper.printIOExp();
                rsaCrypterFile(console);
            }
            Console.Out.WriteLine("\nEncrypted File saved to this Path:");
            Console.Out.WriteLine(cryptFilePath);
            //Put private Key to File
            try
            {
                CryptobyFileManager.putKeyToFile(privateKeyPath, privateKey);
            }
            catch (System.IO.IOException)
            {
                CryptobyHelper.printIOExp();
                rsaCrypterFile(console);
            }
            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();
                rsaCrypterFile(console);
            }
            Console.Out.WriteLine("\nPublic Key File saved to this Path:");
            Console.Out.WriteLine(publicKeyPath);
            // Reset Variables
            initRSAKeyGen(console);
            cryptByte     = null;
            plainByte     = null;
            publicKeyByte = null;
            // Back to Menu rsaCrypter with Enter (Return) Key
            Console.Out.WriteLine("\nGo back to RSA File Crypter Menu: Press Enter");
            CryptobyHelper.pressEnter();
            rsaCrypterFile(console);
        }
Пример #32
0
 private static void aesEncrypterFile(CryptobyConsole console)
 {
     // Input Path to File for encryption
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to File for encryption (Type '" + quit +
                           "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     plainFilePath = scanner.next();
     // Get Bytes from PlainFile
     try
     {
         plainByte = CryptobyFileManager.getBytesFromFile(plainFilePath);
     }
     catch (System.IO.IOException)
     {
         CryptobyHelper.printIOExp();
         aesCrypterFile(console);
     }
     // Input Path saving Path
     scanner = new Scanner(java.lang.System.@in);
     Console.Out.WriteLine("Enter Path to save encrypted File (Type '" + quit +
                           "' to Escape):");
     scanner.useDelimiter("\n");
     if (scanner.hasNext(quit))
     {
         aesCrypterFile(console);
     }
     cryptFilePath = scanner.next();
     // Input Key File for encryption
     key = scanKeyFile(console);
     // Initial AES Crypt Object
     initAESKeyGen(console);
     // Encrypt the String Text with given Key
     Console.Out.WriteLine("\nEncrypting in progress...");
     cryptByte = console.getCore().getCryptSym().encrypt(plainByte, key);
     Console.Out.WriteLine("\nEncryption successfull. Saving File now...");
     //Put encrypted Bytes to File
     try
     {
         CryptobyFileManager.putBytesToFile(cryptFilePath, cryptByte);
     }
     catch (System.IO.IOException ex)
     {
         Logger.getLogger(typeof(RsaUI).FullName).log(Level.SEVERE, null, ex);
     }
     Console.Out.WriteLine("\nEncrypted File saved to this Path:");
     Console.Out.WriteLine(cryptFilePath);
     // Reset Variables
     initAESKeyGen(console);
     cryptByte = null;
     plainByte = null;
     key       = null;
     // Back to File Crypter Menu
     Console.Out.WriteLine("\nGo back to AES File Crypter Menu: Press Enter");
     CryptobyHelper.pressEnter();
     aesCrypterFile(console);
 }
Пример #33
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();
        }