예제 #1
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);
 }
예제 #2
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);
 }
예제 #3
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);
 }
예제 #4
0
 public virtual void testGetEOBString()
 {
     System.Console.Out.WriteLine("getEOBString");
     string expResult = string.Empty;
     string result    = CryptobyHelper.getEOBString();
 }