0

Im trying to generate a symmetric key, which i can use to both encrypt and decrypt a message with the same key, in php.

I've made my way through the php documentation below but can only find public/private key generations: http://www.php.net/manual/en/function.openssl-pkey-new.php

Any ideas on how i can use these key generating functions for making a symmetric key?

Thanks, Joe

J.Bet-Eivazi
  • 117
  • 3
  • 7
  • There are special functions for generating public/private keypairs because the two keys have a special mathematical relationship to each other, but a symmetric key is ideally just a random number with no mathematical relationship to anything. So you want to look at functions for generating cryptographic-quality random numbers. – Wyzard Feb 23 '14 at 15:57

1 Answers1

1

A symetric key is basically a random set of bytes. If you want to use the openssl extension use openssl_random_pseudo_bytes():

$symetric_key = openssl_random_pseudo_bytes($length);
hek2mgl
  • 152,036
  • 28
  • 249
  • 266