Android Question AES_Decrypt in FirebaseMessaging BAD_DECRYPT if app closed

amer bashar

Member
Licensed User
Hi friends,
I`m decrypting with this code :
B4X:
Public Sub AES_DecryptB4A(data As String,  secretkey As String) As String
   
    Dim SU As StringUtils
    Dim kg As KeyGenerator
    Dim C As Cipher
    Dim md As MessageDigest
    Dim Decrypted() As Byte
    kg.Initialize("AES")
    kg.KeyFromBytes(md.GetMessageDigest(secretkey.GetBytes("UTF8"), "MD5"))
  
    C.Initialize("AES/ECB/PKCS5Padding")
 
    Dim Bytes() As Byte = SU.DecodeBase64(data)
    Decrypted = C.Decrypt(Bytes, kg.Key, False)
    Return BytesToString(Decrypted, 0, Decrypted.Length, "UTF8")
   
  
End Sub
It is working very good, but I need to decrypt the messages received by firebase, when putting this function in FirebaseMessaging Receiver Module then its failed to decrypt :
B4X:
(BadPaddingException) javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
This is happening only if the app were closed (not foreground and not background)
if the app is foreground or background then it decrypt fine
and if the app is closed and i am not decrypting then the notification works fine
note : firebase is running fine and as per Erel`s 2023 instructions
Any ideas?
 
Top