Fixes bug on saving Encrypted files on DMs.
Fixes bug when using partial downloads to display videos on DMs.
This commit is contained in:
Binary file not shown.
@@ -54,4 +54,22 @@ class AESGCMTest {
|
||||
|
||||
assertEquals(44201, decrypted.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun videoTest2() {
|
||||
val myCipher =
|
||||
AESGCM(
|
||||
"373d19850ebc8ed5b0fefcca5cd6f27fde9cb6ac54fd32f6b4fad9d68ebe8ee0".hexToByteArray(),
|
||||
"95e67b6874784a54299b58b8990499bd".hexToByteArray(),
|
||||
)
|
||||
|
||||
val encrypted =
|
||||
getInstrumentation().context.assets.open("trouble_video").use {
|
||||
it.readAllBytes()
|
||||
}
|
||||
|
||||
val decrypted = myCipher.decrypt(encrypted)
|
||||
|
||||
assertEquals(1277122, decrypted.size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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