Is it safe to use XOR to encrypt data key using master key I am implementing a hierarchical key system with a randomly generated master key and many randomly generated data keys that should be encrypted using the master key. I am wondering what the best way to encrypt the data keys using the master key is. I am thinking that if I XOR the master key with the data key, that should be simple and safe. Is it? I couldn't find any documentation on this.
XORing a master key (presumably a long term key) with data is a very dangerous idea. If any data key is leaked, then the master key may be easily calculated, thus leaking all keys. ($m$ for the master key, $d_x$ for all data keys)
$$c_x = d_x \oplus m$$
then somehow $d_4$ is leaked
$$m = d_4 \oplus c_4$$
$$d_x = c_x \oplus m$$
You'd be better off applying a block cipher (like AES) instead. One of the main properties of block ciphers is that given the plaintext and ciphertext, it is infeasible to generate the key.
$$c_x = E_m(d_x)$$
then again $d_4$ is leaked (who keeps doing that..) yet $m$ is still hidden.