I don't know a lot about cryptography, but you made this comment:
But you didn't save the key. Instead, you generated a new temporary key in the other method. Do you generate the same key in both methods? It seems to me that if you try to decrypt with a different key than the one you used to encrypt, then problems would occur.
You can't regenerate the key, a random one is generated if you call generateKey() . But you can obtain and store the key by calling key.getEncoded(). Then you can use it later for decryption.