コード例 #1
1
ファイル: Macro.java プロジェクト: bramk/bnd
  int process(CharSequence org, int index, char begin, char end, StringBuilder result, Link link) {
    StringBuilder line = new StringBuilder(org);
    int nesting = 1;

    StringBuilder variable = new StringBuilder();
    outer:
    while (index < line.length()) {
      char c1 = line.charAt(index++);
      if (c1 == end) {
        if (--nesting == 0) {
          result.append(replace(variable.toString(), link));
          return index;
        }
      } else if (c1 == begin) nesting++;
      else if (c1 == '\\' && index < line.length() - 1 && line.charAt(index) == '$') {
        // remove the escape backslash and interpret the dollar
        // as a
        // literal
        index++;
        variable.append('$');
        continue outer;
      } else if (c1 == '$' && index < line.length() - 2) {
        char c2 = line.charAt(index);
        char terminator = getTerminator(c2);
        if (terminator != 0) {
          index = process(line, index + 1, c2, terminator, variable, link);
          continue outer;
        }
      } else if (c1 == '.' && index < line.length() && line.charAt(index) == '/') {
        // Found the sequence ./
        if (index == 1 || Character.isWhitespace(line.charAt(index - 2))) {
          // make sure it is preceded by whitespace or starts at begin
          index++;
          variable.append(domain.getBase().getAbsolutePath());
          variable.append('/');
          continue outer;
        }
      }
      variable.append(c1);
    }
    result.append(variable);
    return index;
  }
コード例 #2
1
 /** Return next string in the sequence "a", "b", ... "z", "aa", "ab", ... */
 static String getNextDirName(String old) {
   StringBuilder sb = new StringBuilder(old);
   // go through and increment the first non-'z' char
   // counts back from the last char, so 'aa'->'ab', not 'ba'
   for (int ii = sb.length() - 1; ii >= 0; ii--) {
     char curChar = sb.charAt(ii);
     if (curChar < 'z') {
       sb.setCharAt(ii, (char) (curChar + 1));
       return sb.toString();
     }
     sb.setCharAt(ii, 'a');
   }
   sb.insert(0, 'a');
   return sb.toString();
 }
コード例 #3
0
  public static void main(String args[]) {
    try {
      // ReceiveMessageInterface rmiclient;
      RmiServer server = new RmiServer();
      // rmiclient=(ReceiveMessageInterface)(registry.lookup("rmiclient"));
      // rmiclient.generateKeys(publicKey);
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
      keyGen.initialize(1024);
      KeyPair keypair = keyGen.genKeyPair();
      publicKey = keypair.getPublic();
      privateKey = keypair.getPrivate();

      BufferedImage image = ImageIO.read(new File("/home/subba/Desktop/test/iris1.bmp"));

      // write it to byte array in-memory (jpg format)
      ByteArrayOutputStream b = new ByteArrayOutputStream();
      ImageIO.write(image, "bmp", b);

      // do whatever with the array...
      byte[] jpgByteArray = b.toByteArray();

      // convert it to a String with 0s and 1s
      StringBuilder sb = new StringBuilder();
      int i = 0;
      for (byte by : jpgByteArray) {
        i++;
        if (i > 366) break;
        sb.append(Integer.toBinaryString(by & 0xFF));
      }
      sb.append("0000000000000000000000000000000000000000000");
      System.out.println(sb.toString().length());
      System.out.println(sb.toString());
      int token = 170;
      StringBuilder sb1 = new StringBuilder();
      sb1.append(Integer.toBinaryString(token));
      for (int j = 0; j < 102; j++) {
        sb1.append("00000000000000000000");
      }
      System.out.println("Binary is " + sb1.length());
      for (i = 0; i < sb.length(); i++) {
        bioTemplate.append(sb.charAt(i) ^ sb1.charAt(i));
      }

      /*MessageDigest digest = MessageDigest.getInstance("SHA-256");
      byte[] hashvalue=serviceProviderKey.getBytes();
      digest.update(hashvalue);
      Phashdigest=digest.digest();
      */

      securePassword = getSecurePassword(serviceProviderKey, "200");
      System.out.println(securePassword);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
コード例 #4
0
  public String sendDetails(String password, byte[] phash, String transactionID, byte[] spdata)
      throws RemoteException, NotBoundException, NoSuchAlgorithmException, NoSuchPaddingException,
          InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.DECRYPT_MODE, privateKey);
    byte[] cipherData = cipher.doFinal(spdata);
    String x = new String(cipherData);
    String sp[] = new String[10];
    StringTokenizer st = new StringTokenizer(x.toString(), "|");
    int count = 0;
    StringBuilder message = new StringBuilder();
    while (st.hasMoreTokens()) {
      sp[count] = st.nextToken();
      count++;
    }

    String decodemessgae = new String();
    if (securePassword.equals(sp[1]) && serviceProviderId.equals(sp[0].toString().trim())) {
      System.out.println("hellosubba");
      if (transactionID.equals(transactionDetails[0].toString())) {
        int qrData[] = new int[16];

        for (int i = 0; i < password.length(); i++) {
          message.append(password.charAt(i) ^ bioTemplate.charAt(i));
        }
        for (int i = 0; i < message.length(); i++) {
          if (message.charAt(i) == '1') {
            decodemessgae += '0';
          } else decodemessgae += '1';
        }
        int start = 56, end = 63;
        for (int i = 0; i < 16; i++) {
          qrData[i] = Integer.parseInt(decodemessgae.substring(start, end), 2);
          start += 64;
          end += 64;
        }
        RsDecode dec = new RsDecode(16);
        int r = dec.decode(qrData);
        System.out.println("r=" + r);
        System.out.println("qrData=" + java.util.Arrays.toString(qrData));

        int[] MM = new int[qrData.length + 16];
        System.arraycopy(qrData, 0, MM, 0, qrData.length);
        RsEncode enc = new RsEncode(16);
        enc.encode(MM);
        System.out.println("qrData=" + java.util.Arrays.toString(MM));
      }
    } else {
      message.append("unkonw third party user");
    }
    return message.toString();
  }