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); }
public virtual void testCharToBlockString() { System.Console.Out.WriteLine("charToBlockString"); byte[] cryptByte = Encoding.UTF8.GetBytes("TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest" ); char[] charTextHex = CryptobyHelper.bytesToHexStringUpper(cryptByte).ToCharArray( ); string result = CryptobyHelper.charToBlockString(charTextHex); System.Console.Out.WriteLine(result); }
public virtual void testPrintHexBlock() { System.Console.Out.WriteLine("printHexBlock"); byte[] cryptByte = Encoding.UTF8.GetBytes("TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest" ); char[] inputCharTextHex = CryptobyHelper.bytesToHexStringUpper(cryptByte).ToCharArray (); string cryptType = "RSA"; int inputKeySize = 1024; string result = CryptobyHelper.printHexBlock(cryptType, inputKeySize, inputCharTextHex ); System.Console.Out.WriteLine(result); }
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); }
public virtual void testEncryptDecrypt256_CBC() { System.Console.Out.WriteLine("encrypt and decrypt recurring words"); byte[] plainInput = Encoding.UTF8.GetBytes("TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest" ); KeyGenSHA3 keyGen = new KeyGenSHA3(); string hexKey = keyGen.generateKey(256, "password"); byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey); CryptAES instance = new CryptAES(); byte[] expResult = plainInput; byte[] result = instance.encrypt(plainInput, bKey); string resString = CryptobyHelper.bytesToHexStringUpper(result); for (int i = 0; i < resString.Length - 32; i += 32) { Assert.IsFalse(resString.Substring(i, 32).Equals (resString.Substring(i + 32, 32))); } result = instance.decrypt(result, bKey); Assert.AreEqual(expResult, result); }
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); }