Package dom

Examples of dom.MessageDO


  public UserDao getUserDao() {
    return userDao;
  }

public boolean isMessageExpired(String messageId) {
  MessageDO message = messageDao.getMessageById(messageId);
    boolean expired = false;
    if (message.isExpired()) { // Check to verify if message is already
                  // expired in some earlier transaction
      expired = true;
    } else if (message.getTimeToLive() != null) // Check to differentiate
    // TTL enabled messages
    {
      Calendar currentDate = GregorianCalendar.getInstance();
      int status = new Timestamp(currentDate.getTime().getTime())
          .compareTo(message.getTimeToLive());
      expired = status == 1;
      if (expired) {
        message.setExpired(true);
        getMessageDao().update(message);
      }
    }
    return expired;
  }
View Full Code Here


public boolean isValidAnswer(String ans, String messageId, boolean oldVersion) {
    if (isMessageExpired(messageId)) {
      throw new RuntimeException(
          "Message is expired and hence, cannot be read.");
    }
    MessageDO messageDetails = getMessageDao().getMessageById(messageId);
    String answer = Normalizer.normalize(ans, Normalizer.Form.NFD);
    byte[] hashedAnswer = null;
    if (oldVersion) {
      hashedAnswer = Util.hash(answer);
    } else {
      hashedAnswer = answer.getBytes();
    }
    // Verifying if correct answer is entered by user or not.
    if (hashedAnswer.length == messageDetails.getAnswer().length) {
      for (int count = 0; count < messageDetails.getAnswer().length; count++) {
        if (hashedAnswer[count] != messageDetails.getAnswer()[count]) {
          return false;
        }
      }
    } else {
      return false;
View Full Code Here

  public String receive(String ans, String messageId, boolean oldVersion) {
    if (isMessageExpired(messageId)) {
      throw new RuntimeException(
          "Message is expired and hence, cannot be read.");
    }
    MessageDO messageDetails = getMessageDao().getMessageById(messageId);
    String answer = Normalizer.normalize(ans, Normalizer.Form.NFD);
    byte[] hashedAnswer = null;
    if (oldVersion) {
      hashedAnswer = Util.hash(answer);
    } else {
      hashedAnswer = answer.getBytes();
    }

    // Verifying if correct answer is entered by user or not.
    try {
      ElGamalPrivateKey privateKey = Util.decryptPrivateKey(
          messageDetails.getPrvKey(), hashedAnswer);
      return Util.decrypt(messageDetails.getMessageKey(), privateKey);
    } catch (Exception e1) {
      e1.printStackTrace();
    }
    return null;
  }
View Full Code Here

      try {
        con = Util.getConnection();
        ps = con.prepareStatement(query);
        ps.setString(1, messageId);
        rs = ps.executeQuery();
        MessageDO message = null;
        if (rs.next()) {
          message = new MessageDO();
          message.setMessageId(messageId);
          message.setMessageKey(rs.getBytes("messageKey"));
          message.setPrvKey(rs.getBytes("prvKey"));
          message.setfromMail(rs.getString("fromMail"));
          message.settoMail(rs.getString("toMail"));       
          message.setQuestion(rs.getString("question"));
          message.setAnswer(rs.getBytes("answer"));
          message.setExpired(rs.getBoolean("expired"));
          message.setTimeToLive(rs.getTimestamp("timeToLive"));
          }
         return message;
        }
      catch (SQLException e) {e.printStackTrace();}
      finally {
View Full Code Here

    }
    return messageId;
  }

public boolean isver1 (String messageId) {
    MessageDO message = messageDao.getMessageById(messageId);
    if(message.getfromMail() != "empty.server")
    {
      return true;
    }
    else return false;
}
View Full Code Here

TOP

Related Classes of dom.MessageDO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.