Skip to content

Commit

Permalink
Decryption still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
reznik99 committed Nov 9, 2022
1 parent a0fd213 commit 858c87e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/global/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export async function decryptAESGCM(sessionKey: CryptoKey, encryptedMessage: str
const decrypted = await window.crypto.subtle.decrypt(
{
name: "AES-GCM",
iv: Buffer.from(IV, 'base64')
iv: Buffer.from(IV, 'base64'),
additionalData: new Uint8Array(),
tagLength: 128
},
sessionKey,
Buffer.from(cipherText, 'base64')
Expand All @@ -92,11 +94,13 @@ export async function decryptAESGCM(sessionKey: CryptoKey, encryptedMessage: str
export async function encryptAESGCM(sessionKey: CryptoKey, message: string): Promise<string> {


const IV = window.crypto.getRandomValues(new Uint8Array(12));
const IV = window.crypto.getRandomValues(new Uint8Array(12));
const cipherText = await window.crypto.subtle.encrypt(
{
name: "AES-GCM",
iv: IV
iv: IV,
additionalData: new Uint8Array(),
tagLength: 128
},
sessionKey,
Buffer.from(message, 'ascii')
Expand Down
4 changes: 3 additions & 1 deletion src/pages/conversation/Conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export default function Conversation(props) {
{
data && data.messages ? data.messages.map((packet, index) => {
return packet.sender === state.user_data.phone_no
? <Text key={index} style={[styles.message, styles.sent]}>{packet.message}</Text>
? <TouchableOpacity key={index} style={styles.button} onPress={() => decryptMessage(index+"", packet.message)}>
<Text key={index} style={[styles.message, styles.sent]}>{packet.message}</Text>
</TouchableOpacity>
: <TouchableOpacity key={index} style={styles.button} onPress={() => decryptMessage(index+"", packet.message)}>
<Text style={[styles.message, styles.received]}>{decryptedMessages.get(index + "") || packet.message}</Text>
</TouchableOpacity>
Expand Down

0 comments on commit 858c87e

Please sign in to comment.