예제 #1
0
        public virtual void testPrintPublicKeyBlock()
        {
            System.Console.Out.WriteLine("printPublicKeyBlock");
            string publicKey = "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest";
            string result    = CryptobyHelper.printPublicKeyBlock(publicKey);

            System.Console.Out.WriteLine(result);
        }
예제 #2
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);
        }
예제 #3
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();
        }