diff --git a/TalkIn/app/src/main/java/com/example/talk_in/AESUtils.java b/TalkIn/app/src/main/java/com/example/talk_in/AESUtils.java deleted file mode 100644 index bbf199b..0000000 --- a/TalkIn/app/src/main/java/com/example/talk_in/AESUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.example.talk_in; - -import javax.crypto.Cipher; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; - -public class AESUtils -{ - - private static final byte[] keyValue = - new byte[]{'c', 'o', 'd', 'i', 'n', 'g', 'a', 'f', 'f', 'a', 'i', 'r', 's', 'c', 'o', 'm'}; - - - public static String encrypt(String cleartext) - throws Exception { - byte[] rawKey = getRawKey(); - byte[] result = encrypt(rawKey, cleartext.getBytes()); - return toHex(result); - } - - public static String decrypt(String encrypted) - throws Exception { - - byte[] enc = toByte(encrypted); - byte[] result = decrypt(enc); - return new String(result); - } - - private static byte[] getRawKey() throws Exception { - SecretKey key = new SecretKeySpec(keyValue, "AES"); - byte[] raw = key.getEncoded(); - return raw; - } - - private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception { - SecretKey skeySpec = new SecretKeySpec(raw, "AES"); - Cipher cipher = Cipher.getInstance("AES"); - cipher.init(Cipher.ENCRYPT_MODE, skeySpec); - byte[] encrypted = cipher.doFinal(clear); - return encrypted; - } - - private static byte[] decrypt(byte[] encrypted) - throws Exception { - SecretKey skeySpec = new SecretKeySpec(keyValue, "AES"); - Cipher cipher = Cipher.getInstance("AES"); - cipher.init(Cipher.DECRYPT_MODE, skeySpec); - byte[] decrypted = cipher.doFinal(encrypted); - return decrypted; - } - - public static byte[] toByte(String hexString) { - int len = hexString.length() / 2; - byte[] result = new byte[len]; - for (int i = 0; i < len; i++) - result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), - 16).byteValue(); - return result; - } - - public static String toHex(byte[] buf) { - if (buf == null) - return ""; - StringBuffer result = new StringBuffer(2 * buf.length); - for (int i = 0; i < buf.length; i++) { - appendHex(result, buf[i]); - } - return result.toString(); - } - - private final static String HEX = "0123456789ABCDEF"; - - private static void appendHex(StringBuffer sb, byte b) { - sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f)); - } -} \ No newline at end of file diff --git a/TalkIn/app/src/main/java/com/example/talk_in/ChatActivity.kt b/TalkIn/app/src/main/java/com/example/talk_in/ChatActivity.kt index 1eb8f8d..9a874e1 100644 --- a/TalkIn/app/src/main/java/com/example/talk_in/ChatActivity.kt +++ b/TalkIn/app/src/main/java/com/example/talk_in/ChatActivity.kt @@ -95,7 +95,7 @@ class ChatActivity : AppCompatActivity() { if (!replyMessage.isNullOrEmpty() && intent.getBooleanExtra("fromNotification", false)) { // If a reply message is received from notification, send it to the receiver isReplyingFromNotification = true - val messageObject = Message(AESUtils.encrypt(replyMessage), senderUid, System.currentTimeMillis()) + val messageObject = Message(replyMessage, senderUid, System.currentTimeMillis()) sendMessage(messageObject) } @@ -117,7 +117,7 @@ class ChatActivity : AppCompatActivity() { sendButton.setOnClickListener { val messageText = messageBox.text.toString().trim() if (messageText.isNotEmpty()) { - val messageObject = Message(AESUtils.encrypt(messageText), senderUid, System.currentTimeMillis()) + val messageObject = Message(messageText, senderUid, System.currentTimeMillis()) sendMessage(messageObject) messageBox.setText("") } @@ -176,7 +176,7 @@ class ChatActivity : AppCompatActivity() { messageList.clear() var currentDate: String? = null for (postSnapshot in snapshot.children) { - var message = postSnapshot.getValue(Message::class.java) + val message = postSnapshot.getValue(Message::class.java) message?.let { // Get the date from the timestamp val date = getDateFromTimestamp(it.timestamp ?: 0L) @@ -285,4 +285,4 @@ class ChatActivity : AppCompatActivity() { currentChatUser = null isActive = false } -} \ No newline at end of file +} diff --git a/TalkIn/app/src/main/java/com/example/talk_in/Message.kt b/TalkIn/app/src/main/java/com/example/talk_in/Message.kt index 4bc62b9..72f546b 100644 --- a/TalkIn/app/src/main/java/com/example/talk_in/Message.kt +++ b/TalkIn/app/src/main/java/com/example/talk_in/Message.kt @@ -1,8 +1,8 @@ package com.example.talk_in data class Message( - var message: String? = null, + val message: String? = null, val senderId: String? = null, val timestamp: Long? = null, val isDateSection: Boolean = false -) \ No newline at end of file +) diff --git a/TalkIn/app/src/main/java/com/example/talk_in/MessageAdapter.kt b/TalkIn/app/src/main/java/com/example/talk_in/MessageAdapter.kt index 1d719f0..4742e70 100644 --- a/TalkIn/app/src/main/java/com/example/talk_in/MessageAdapter.kt +++ b/TalkIn/app/src/main/java/com/example/talk_in/MessageAdapter.kt @@ -1,7 +1,6 @@ package com.example.talk_in import android.content.Context -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -12,7 +11,7 @@ import java.text.SimpleDateFormat import java.util.* class MessageAdapter(private val context: Context, private var messageList: ArrayList) : - RecyclerView.Adapter() { + RecyclerView.Adapter() { private val ITEM_RECEIVE = 1 private val ITEM_SENT = 2 @@ -55,11 +54,11 @@ class MessageAdapter(private val context: Context, private var messageList: Arra when (holder) { is SentViewHolder -> { - holder.sentMessage.text = AESUtils.decrypt(currentMessage.message.toString()) + holder.sentMessage.text = currentMessage.message holder.sendTimestamp.text = formattedTime } is ReceiveViewHolder -> { - holder.receiveMessage.text = AESUtils.decrypt(currentMessage.message.toString()) + holder.receiveMessage.text = currentMessage.message holder.receiveTimestamp.text = formattedTime } } @@ -90,4 +89,4 @@ class MessageAdapter(private val context: Context, private var messageList: Arra class DateViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val dateTextView: TextView = itemView.findViewById(R.id.date_section_text) } -} \ No newline at end of file +} diff --git a/TalkIn/app/src/main/java/com/example/talk_in/UserAdapter.kt b/TalkIn/app/src/main/java/com/example/talk_in/UserAdapter.kt index 2ef8950..83d60cf 100644 --- a/TalkIn/app/src/main/java/com/example/talk_in/UserAdapter.kt +++ b/TalkIn/app/src/main/java/com/example/talk_in/UserAdapter.kt @@ -61,7 +61,7 @@ class UserAdapter(val context: Context, val userList: ArrayList) : override fun onDataChange(snapshot: DataSnapshot) { if (snapshot.exists()) { val lastMessage = snapshot.children.first().getValue(Message::class.java) - holder.txt_last_message.setText(AESUtils.decrypt(lastMessage?.message.toString())) + holder.txt_last_message.setText(lastMessage?.message.toString()) } else{ var aboutUser = currentUser.aboutMe.toString().trim()