I was just wondering is it redundant to encrypt and sign a cookie? Isn't encryption enough? Why or why not?
If it's not redundant, I'm wondering if I'm going about this in the right direction. For simplicity's sake, what I've done is this:
$data = 'some data';
$encrypted_data = mcrypt_encrypt($cipher, $key, $data, $mode, $iv);
$signature = hash_hmac($algorithm, $data, $key);
$package = $encrypted_data . '|' . $signature;
setcookie('somecookie', $package, time()+60*60*24);
From what I basically understand is, you're hmac hashing the data and with a delimiter you're appending it onto your encrypted data? Then later you do all your validation and so on when you're checking the cookie. Am I approaching this correctly? Also, should all the keys for encryption and signing be nonces (single time used key) or is it enough for each of them to be a single global key shared by all? I apologize that this is becoming a 3-parter question. Hope that no one minds. Thanks a lot.