Generating a symmetric key in php

走远了吗. 提交于 2019-12-11 22:07:28

问题


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


回答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);


来源:https://stackoverflow.com/questions/21970478/generating-a-symmetric-key-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!