Android Kotlin AES/GCM Entschlüsselung javax.crypto.aeadbadtagexceptionJava

Java-Forum
Anonymous
 Android Kotlin AES/GCM Entschlüsselung javax.crypto.aeadbadtagexception

Post by Anonymous »

Ich versuche, eine in AES mit dem GCM -Modus codierte Zeichenfolge durch eine andere Anwendung zu entschlüsseln.

Code: Select all

javax.crypto.AEADBadTagException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at com.android.org.conscrypt.OpenSSLCipher$EVP_AEAD.throwAEADBadTagExceptionIfAvailable(OpenSSLCipher.java:1216)
at com.android.org.conscrypt.OpenSSLCipher$EVP_AEAD.doFinalInternal(OpenSSLCipher.java:1245)
at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:363)
at javax.crypto.Cipher.doFinal(Cipher.java:2055)
at fr.lundimatin.core.utils.AESEncryptionUtil$Companion.decrypt(AESEncryptionUtil.kt:40)
< /code>
Ich verwende eine Methode, um den String der Verschlüsselungsschlüssel zu konvertieren.const val IV_LENGTH = 16

fun getSecretKey(key: String) : SecretKey
{
val decodedKey: ByteArray = Base64.getDecoder().decode(key)
val originalKey: SecretKey = SecretKeySpec(decodedKey, 0, decodedKey.size, "AES")
return originalKey
}

//message : "MjY2NjI4QkI0NDYwRTExMxPQoQrBDTPMWTTIAhJ5QH4cKjzmWIIfW0mBv3zIC7yHJr5nqfmmEYk34BW9ag=="
fun decrypt(message: String): String {
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
val ivString = message.substring(0, IV_LENGTH)
val ivEncrypted = Base64.getDecoder().decode(ivString)
val spec = GCMParameterSpec(128, ivEncrypted)
cipher.init(Cipher.DECRYPT_MODE, getEncryptionKey(), spec)
val messageEncrypted = Base64.getDecoder().decode(message.substring(IV_LENGTH))
val decryptedBytes = cipher.doFinal(messageEncrypted)
return String(decryptedBytes, StandardCharsets.UTF_8) // 400172870-327468066356882-CHE
}

fun getEncryptionKey() : SecretKey {
return getSecretKey("k8h1k9LyiHgcStf/crHlkw==")
}
Leider ist die Nachricht nicht sehr hilfreich und ich habe keine Lösung für Stackoverflow gefunden, die für meinen Fall gelten würde.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post