在PHP中生成对称密钥 [英] Generating a symmetric key in php

查看:161
本文介绍了在PHP中生成对称密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成对称密钥,我可以用它在php中使用相同的密钥对消息进行加密和解密.

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

我已经通过下面的php文档进行了操作,但是只能找到公共/私有密钥世代: http://www.php.net/manual/zh/function .openssl-pkey-new.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?

谢谢, 乔

推荐答案

symetric 密钥基本上是一组随机字节.如果要使用openssl扩展名,请使用 openssl_random_pseudo_bytes() :

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

这篇关于在PHP中生成对称密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆