In general, for a contant-coefficient homogeneous linear differential equation $P(D) y = 0$, where $D = \frac{d}{dx}$ and $P$ is a polynomial of degree $n$ with $n$ distinct roots $r_1, \ldots, r_n$, the general solution is $y(x) = \sum_{j=1}^n c_j e^{r_j x}$ where $c_1, \ldots, c_n$ are arbitrary constants. In your case, assuming $k \ne 0$, $P(t) = t^2 + k^2$ has the two roots $\pm k i$, so the general solution is $y(x) = c_1 e^{ikx} + c_2 e^{-ikx}$. Since $e^{ikx} = \cos(kx) + i \sin(kx)$, an alternate form of the general solution is $y(x) = A \cos(k x) + B \sin(k x)$, where $A = c_1 + c_2$ and $B = i c_1 - i c_2$.