5. $a$ is a parameter, the function
$$
f(x)=(x+a) 3^{x-2+a^{2}}-(x-a) 3^{8-x-3 a}
$$
is an even function. Then the set of values that $a$ can take is ( ).
(A) $\{0,5\}$
(B) $\{-2,5\}$
(C) $\{-5,2\}$
(D) $\{1,2009\}$
5. C.

Given that the function $f(x)$ is an even function, we know that $f(-a)=f(a)$, which means $2 a \cdot 3^{8+a-3 a}=2 a \cdot 3^{a-2+a^{2}}$.
Thus, $a=0$ or $8+a-3 a=a-2+a^{2}$.
If $a=0$, then $f(x)=x\left(3^{x-2}-3^{8-x}\right)$ is not an even function. Therefore, $a \neq 0$.

If $8+a-3 a=a-2+a^{2}$, then $a=-5$ or 2, in which case, the functions
$$
f(x)=-(5-x) 3^{23+x}-(5+x) 3^{23-x}
$$

and $f(x)=(2+x) 3^{2+x}+(2-x) 3^{2-x}$ are both even functions.