Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
  public void sendData(
      String fileName,
      PCBC pcbc,
      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 = pcbc.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();
    }
  }