首页 > 其他分享 >openssl 加密

openssl 加密

时间:2023-11-10 09:46:51浏览次数:34  
标签:cbc aes 加密 aria openssl 192 128 256

对称加密算法查询,显示当前环境下所有支持的算法列表。
print_r(openssl_get_cipher_methods());
php8.1.11 的加密算法
[0] => aes-128-cbc
    [1] => aes-128-cbc-hmac-sha1
    [2] => aes-128-cbc-hmac-sha256
    [3] => aes-128-ccm
    [4] => aes-128-cfb
    [5] => aes-128-cfb1
    [6] => aes-128-cfb8
    [7] => aes-128-ctr
    [8] => aes-128-ecb
    [9] => aes-128-gcm
    [10] => aes-128-ocb
    [11] => aes-128-ofb
    [12] => aes-128-xts
    [13] => aes-192-cbc
    [14] => aes-192-ccm
    [15] => aes-192-cfb
    [16] => aes-192-cfb1
    [17] => aes-192-cfb8
    [18] => aes-192-ctr
    [19] => aes-192-ecb
    [20] => aes-192-gcm
    [21] => aes-192-ocb
    [22] => aes-192-ofb
    [23] => aes-256-cbc
    [24] => aes-256-cbc-hmac-sha1
    [25] => aes-256-cbc-hmac-sha256
    [26] => aes-256-ccm
    [27] => aes-256-cfb
    [28] => aes-256-cfb1
    [29] => aes-256-cfb8
    [30] => aes-256-ctr
    [31] => aes-256-ecb
    [32] => aes-256-gcm
    [33] => aes-256-ocb
    [34] => aes-256-ofb
    [35] => aes-256-xts
    [36] => aria-128-cbc
    [37] => aria-128-ccm
    [38] => aria-128-cfb
    [39] => aria-128-cfb1
    [40] => aria-128-cfb8
    [41] => aria-128-ctr
    [42] => aria-128-ecb
    [43] => aria-128-gcm
    [44] => aria-128-ofb
    [45] => aria-192-cbc
    [46] => aria-192-ccm
    [47] => aria-192-cfb
    [48] => aria-192-cfb1
    [49] => aria-192-cfb8
    [50] => aria-192-ctr
    [51] => aria-192-ecb
    [52] => aria-192-gcm
    [53] => aria-192-ofb
    [54] => aria-256-cbc
    [55] => aria-256-ccm
    [56] => aria-256-cfb
    [57] => aria-256-cfb1
    [58] => aria-256-cfb8
    [59] => aria-256-ctr
    [60] => aria-256-ecb
    [61] => aria-256-gcm
    [62] => aria-256-ofb
    [63] => bf-cbc
    [64] => bf-cfb
    [65] => bf-ecb
    [66] => bf-ofb
    [67] => camellia-128-cbc
    [68] => camellia-128-cfb
    [69] => camellia-128-cfb1
    [70] => camellia-128-cfb8
    [71] => camellia-128-ctr
    [72] => camellia-128-ecb
    [73] => camellia-128-ofb
    [74] => camellia-192-cbc
    [75] => camellia-192-cfb
    [76] => camellia-192-cfb1
    [77] => camellia-192-cfb8
    [78] => camellia-192-ctr
    [79] => camellia-192-ecb
    [80] => camellia-192-ofb
    [81] => camellia-256-cbc
    [82] => camellia-256-cfb
    [83] => camellia-256-cfb1
    [84] => camellia-256-cfb8
    [85] => camellia-256-ctr
    [86] => camellia-256-ecb
    [87] => camellia-256-ofb
    [88] => cast5-cbc
    [89] => cast5-cfb
    [90] => cast5-ecb
    [91] => cast5-ofb
    [92] => chacha20
    [93] => chacha20-poly1305
    [94] => des-cbc
    [95] => des-cfb
    [96] => des-cfb1
    [97] => des-cfb8
    [98] => des-ecb
    [99] => des-ede
    [100] => des-ede-cbc
    [101] => des-ede-cfb
    [102] => des-ede-ofb
    [103] => des-ede3
    [104] => des-ede3-cbc
    [105] => des-ede3-cfb
    [106] => des-ede3-cfb1
    [107] => des-ede3-cfb8
    [108] => des-ede3-ofb
    [109] => des-ofb
    [110] => desx-cbc
    [111] => id-aes128-CCM
    [112] => id-aes128-GCM
    [113] => id-aes128-wrap
    [114] => id-aes128-wrap-pad
    [115] => id-aes192-CCM
    [116] => id-aes192-GCM
    [117] => id-aes192-wrap
    [118] => id-aes192-wrap-pad
    [119] => id-aes256-CCM
    [120] => id-aes256-GCM
    [121] => id-aes256-wrap
    [122] => id-aes256-wrap-pad
    [123] => id-smime-alg-CMS3DESwrap
    [124] => rc2-40-cbc
    [125] => rc2-64-cbc
    [126] => rc2-cbc
    [127] => rc2-cfb
    [128] => rc2-ecb
    [129] => rc2-ofb
    [130] => rc4
    [131] => rc4-40
    [132] => rc4-hmac-md5
    [133] => seed-cbc
    [134] => seed-cfb
    [135] => seed-ecb
    [136] => seed-ofb
    [137] => sm4-cbc
    [138] => sm4-cfb
    [139] => sm4-ctr
    [140] => sm4-ecb
    [141] => sm4-ofb
获取当前算法需要的 iv 长度
openssl_cipher_iv_length()

 生成一个随机的符合算法长度的 iv 内容

openssl_random_pseudo_bytes() 

 加密

openssl_encrypt($data, $method, $key, $options, $iv);

 $data 是需要加密的字符串

 $method 是加密算法

 $key 是加密的密钥

 $options 有两个可选常量:OPENSSL_RAW_DATA 和 OPENSSL_ZERO_PADDING

  OPENSSL_RAW_DATA:加密后的数据将按照原样返回(二进制乱码内容)

  OPENSSL_ZERO_PADDING :加密后的数据将返回为 base64 之后的内容

 $iv:向量

openssl_encrypt函数默认使用的是PKCS7填充(不是PKCS5填充)。PKCS7填充实际上是PKCS5填充的扩展,用于对不同块大小的数据进行填充。

 

解密

openssl_decrypt($data, $method, $key, $options, $iv);

  

 

标签:cbc,aes,加密,aria,openssl,192,128,256
From: https://www.cnblogs.com/zinging/p/17823365.html

相关文章

  • C#简单的MD5加密
    MD5(MessageDigestAlgorithm5)是一种常见的哈希函数,用于将任意长度的输入数据通过计算生成固定长度的128位哈希值。MD5哈希值通常以十六进制字符串的形式表示,常被用于对密码、消息等敏感信息进行加密或摘要处理。在编程中,可以使用现有的加密库或工具来对数据进行MD5加密。在......
  • 使用PHP实现对称加密和解密过程,真的是太简单了!
    ......
  • 五种实现数据加密存储的方式,你选择哪一种
    前言最近由于项目需要做等保,其中有一项要求是系统中的个人信息和业务信息需要进行加密存储。经过一番搜索,最终总结出了五种数据加密存储的方法(结合SpringBoot和MyBatisPlus框架进行实现),不知道家人们在项目中使用的是哪种方式......
  • Unity项目开发中如何做资源加密
    Unity的游戏很容易被人反编译出来,然后再重新打包发布,把自己辛辛苦苦开发的游戏,抄写的一丝不挂。很多项目要求要做好资源加密,Unity中如何做好资源加密呢?本文給大家分享加密算法+资源打包整合思路:(1) 游戏资源加密如何选择加密算法;(2) Assetsbundle资源包的加密与解密;  ......
  • 某音用SSL证书上了一把“安全锁”,加密保护网络传输数据安全
    依照《网络安全法》、《数据安全法》等相关法律法规,网络运营者应当按照网络安全等级保护制度的要求,采用数据加密等措施来防止网络数据泄露或者被窃取、篡改。某音作为头部的音乐创意短视频社交平台,每天都有数以亿计的用户在上面观看、发布视频,而这会产生大量包含个人账号、密码等用......
  • ERROR: dependencies ‘openssl’, ‘curl’ are not available for package ‘creden
     001、问题:R语言安装“devtools” ERROR:dependencies‘openssl’,‘curl’arenotavailableforpackage‘credentials’ 002、解决方法: ......
  • 微信小程序【同城配送】及【加密请求】
    在小程序后台配置API安全时注意保存密钥,要不然还得重新弄。封装属性配置类,在加解密的时候会用到封装加解密方法使用okhttp封装post加密请求,并将信息解密调用post方法将必要信息加密后发送给微信并得到相应,对其解密对信息进行业务处理封装属性配置类创建一个config.proper......
  • 第4章 高级加密标准
    4.1高级加密标准的起源严格地说,AES和Rijndael加密法并不完全一样(虽然在实际应用中二者可以互换),因为Rijndael加密法可以支持更大范围的分组和密钥长度:AES的分组长度固定为128比特,密钥长度则可以是128比特、192比特或256比特;而Rijndael使用的密钥和分组长度可以是32比特的整数倍,以......
  • Base64编码、解码 C语言例子(使用OpenSSL库)
    #include<stdio.h>#include<string.h>#include<unistd.h>#include<openssl/pem.h>#include<openssl/bio.h>#include<openssl/evp.h>intbase64_encode(char*in_str,intin_len,char*out_str){BIO*b64,*bio;......
  • 对称加密与非对称加密有什么区别?RSA和AES算法有什么区别?
    对称加密与非对称加密有什么区别?对称加密:指加密和解密使用同一密钥,优点是运算速度较快,缺点是如何安全将密钥传输给另一方。常见的对称加密算法有:DES、AES等。非对称加密:指的是加密和解密使用不同的密钥(即公钥和私钥)。公钥与私钥是成对存在的,如果用公钥对数据进行加密,只有对应的私......