which I use to en-/decrypt data via C native code which runs like a charm. Problem here is that it of course always uses 256 bytes even if the data is shorter (filled with zero bytes). I then copy it to a new byte array with the real length.
Question: Is there a better way? (dynamic allocation or similar)
Dynamic allocation is problematic as it will lead to heap fragmentation and will eventually cause your program to fail.
Your method is actually better as long as the memory required is always smaller than the preset size. The memory used is constant and it can run forever.