Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a key in PHP for AES 256

Tags:

php

key

aes

How can I securely generate a key suitable for hashing data with AES 256 using PHP?

I've tried Googling and found plenty of information about how to encrypt data using AES 256 using PHP, however all of these examples used existing pre-generated keys, wheras I need to generate the key in PHP.

like image 931
fibi Avatar asked Oct 21 '25 00:10

fibi


1 Answers

The openssl-pkey-new() function is exactly what you are looking for.

As for the IV, you can look at How to securely generate an IV for AES CBC Encryption? which recommends using openssl-random-pseudo-bytes

But if you are really looking for a helpful page, Google "Implement AES in PHP" - as the first hit you will find http://www.movable-type.co.uk/scripts/aes-php.html which surely will teach you everything you need to know...

like image 188
Floris Avatar answered Oct 23 '25 16:10

Floris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!