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;
}