Beispiel #1
0
  public String decHashValue(String Cipher_Chosen, String hashValue) {
    //        System.out.println("Decrypting hash message --" + hashValue);
    String decHashValue = null;

    if (Cipher_Chosen.equalsIgnoreCase("rc4")) {
      RC4 rc4 = new RC4(new String(key1));
      byte[] cipher = hashValue.getBytes();
      byte[] deText = rc4.decrypt(cipher);
      decHashValue = new String(deText);
    } else if (Cipher_Chosen.equalsIgnoreCase("cbc")) {
      CBC cbc = new CBC(key1, key2);
      byte[] enText = hashValue.getBytes();
      decHashValue = cbc.decrypt(enText);
    } else if (Cipher_Chosen.equalsIgnoreCase("pcbc")) {
      PCBC pcbc = new PCBC(key1, key2);
      byte[] enText = hashValue.getBytes();
      decHashValue = pcbc.decrypt(enText);
    } else if (Cipher_Chosen.equalsIgnoreCase("cfb")) {
      // Cipher chosen is CFB
      CFB cfb = new CFB(key1, key2);
      byte[] enText = hashValue.getBytes();
      decHashValue = cfb.decrypt(enText);
    }

    return decHashValue;
  }
Beispiel #2
0
 public String encHashValue(String Cipher_Chosen, String hashValue) {
   //        System.out.println("Encrypting hash message --" + hashValue);
   String encHashValue = null;
   if (Cipher_Chosen.equalsIgnoreCase("rc4")) {
     RC4 rc4 = new RC4(new String(key1));
     byte[] plain = hashValue.getBytes();
     byte[] eText = rc4.encrypt(plain);
     encHashValue = new String(eText);
   } else if (Cipher_Chosen.equalsIgnoreCase("cbc")) {
     CBC cbc = new CBC(key1, key2);
     byte[] eText = cbc.encrypt(hashValue);
     encHashValue = new String(eText);
   } else if (Cipher_Chosen.equalsIgnoreCase("pcbc")) {
     PCBC pcbc = new PCBC(key1, key2);
     byte[] eText = pcbc.encrypt(hashValue);
     encHashValue = new String(eText);
   } else if (Cipher_Chosen.equalsIgnoreCase("cfb")) {
     // Cipher chosen is CFB
     CFB cfb = new CFB(key1, key2);
     byte[] eText = cfb.encrypt(hashValue);
     encHashValue = new String(eText);
   }
   return encHashValue;
 }
Beispiel #3
0
  public void sendData(
      String fileName, CBC cbc, InputStream sockIn, OutputStream sockOut, boolean eve, int action) {

    DataOutputStream dout;
    BufferedReader brin;
    try {
      dout = new DataOutputStream(sockOut);
      brin = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));

      String line;
      byte[] enText;
      while ((line = brin.readLine()) != null) {
        if (line.equalsIgnoreCase("")) {
          continue;
        }
        enText = cbc.encrypt(line);

        // Evesdropper action
        switch (action) {
          case 0:
            break;
          case 1:
            int len1 = enText.length;
            if (len1 >= 8) {
              for (int i = 0; i < 8; i++) {
                enText[i] = (byte) (i + 3 % 256);
              }
            }
            break;
          case 2:
            int len2 = enText.length;
            if (len2 > 8) {
              byte[] remove = new byte[len2 - 8];
              System.arraycopy(enText, 8, enText, 0, len2 - 8);
              enText = remove;
            }
            break;
          case 3:
            int len3 = enText.length;
            byte[] add = new byte[len3 + 8];
            byte[] dump = new byte[8];
            for (int i = 0; i < 8; i++) {
              dump[i] = (byte) (i + 3 % 256);
            }
            System.arraycopy(dump, 0, add, 0, 8);
            System.arraycopy(enText, 0, add, 8, len3);
            enText = add;

            break;
          default:
            break;
        }

        dout.writeInt(enText.length);
        dout.write(enText);
        System.out.println(line);
        System.out.println(new String(enText));
      }

      dout.close();
      brin.close();

    } catch (FileNotFoundException fnfe) {
      System.out.println("*******File not found*****");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }