The docs for attr_encrypted
say that I must store the results of key = SecureRandom.random_bytes(32)
on the model. I think that it would be more secure to have this key stored as an ENV variable. I am also accustomed to running rake secret
for my ENV variables. rake secret
relies on SecureRandom.hex()
.
I'm wondering two things:
- Am I right to assume that the encryption key should be stored as an ENV variable?
- Is there any difference in key encryption strength between either of the two SecureRandom methods?
hex()
vsrandom_bytes()
?