Fixes bug on saving Encrypted files on DMs.
Fixes bug when using partial downloads to display videos on DMs.
This commit is contained in:
@@ -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?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user