Fixes bug on saving Encrypted files on DMs.

Fixes bug when using partial downloads to display videos on DMs.
This commit is contained in:
Vitor Pamplona
2025-02-25 16:43:15 -05:00
parent d5d289a834
commit e6cd3a99c5
12 changed files with 194 additions and 36 deletions
@@ -20,8 +20,10 @@
*/
package com.vitorpamplona.quartz.nip04Dm.crypto
import android.util.Log
import com.vitorpamplona.quartz.nip17Dm.files.encryption.NostrCipher
import com.vitorpamplona.quartz.utils.RandomInstance
import java.security.GeneralSecurityException
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
@@ -50,6 +52,14 @@ class AESCBC(
doFinal(bytesToDecrypt)
}
override fun decryptOrNull(bytesToDecrypt: ByteArray): ByteArray? =
try {
decrypt(bytesToDecrypt)
} catch (e: GeneralSecurityException) {
Log.w("AESCBC", "Failed to decrypt", e)
null
}
companion object {
const val NAME = "aes-cbc"
}
@@ -20,8 +20,10 @@
*/
package com.vitorpamplona.quartz.nip17Dm.files.encryption
import android.util.Log
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.utils.RandomInstance
import java.security.GeneralSecurityException
import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec
@@ -56,6 +58,14 @@ class AESGCM(
doFinal(bytesToDecrypt)
}
override fun decryptOrNull(bytesToDecrypt: ByteArray): ByteArray? =
try {
decrypt(bytesToDecrypt)
} catch (e: GeneralSecurityException) {
Log.w("AESGCM", "Failed to decrypt", e)
null
}
companion object {
const val NAME = "aes-gcm"
}
@@ -26,4 +26,6 @@ interface NostrCipher {
fun encrypt(bytesToEncrypt: ByteArray): ByteArray
fun decrypt(bytesToDecrypt: ByteArray): ByteArray
fun decryptOrNull(bytesToDecrypt: ByteArray): ByteArray?
}