我阅读了很多php联机帮助页,但只在上下文中找到了有关SNI支持的信息 - http://www.php.net/manual/en/context.ssl.php
当PHP作为服务器工作时,是否可以通过浏览器获取SNI?使用标准stream_socket_server()创建服务器,如例如.这篇文章:http://www.php.net/manual/en/function.stream-socket-server.php#98616
如果我手动将我的字符串填充到32的长度,我的代码就可以工作了.
我的问题是:有没有办法让openSSL填充数据,或者我总是必须为它做这个吗?
工作:
openssl_encrypt ("my baba is over the ocean1111111", 'AES-256-CBC', $MY_SECRET_KEY,OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING,$MY_IV);
Run Code Online (Sandbox Code Playgroud)
不工作:
openssl_encrypt ("my baba is over the ocean", 'AES-256-CBC', $MY_SECRET_KEY,OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING,$MY_IV);
Run Code Online (Sandbox Code Playgroud)
我目前通过自填充来解决这个问题:
$pad = 32 - (strlen("my baba is over the ocean") % 32);
$clear = "my baba is over the ocean" . str_repeat(chr($pad), $pad); //encrypt this string
Run Code Online (Sandbox Code Playgroud) 我正在使用 TCPDF 生成 pdf 文档并对其进行签名。TCPDF本身只是调用PHP的openssl_pkcs7_sign函数,在我看来这是PKCS7_sign基于源代码调用C的函数。
直到最近,一切都运转良好。然后我改变了证书提供者。我刚刚更新了私钥、证书和证书链:
$pdf->setSignature(
$this->public_certificate_path,
$this->private_key_path,
$this->private_key_password,
$this->extra_certificates_path,
1);
Run Code Online (Sandbox Code Playgroud)
我将 PEM 格式的新根证书和中间证书复制到extra_certificates_path文件内。我使用验证了这个文件openssl,看起来不错。
现在,当我在 Adobe Reader 中打开签名的 PDF 时,它会显示以下错误:
该文件已损坏但正在修复
认证无效
已通过 %s 认证
此签名中包含的格式或信息有错误(支持信息:SigDict /Contents非法数据)
请参阅下面的屏幕截图。
知道可能出了什么问题吗?
我试图通过使用对称和非对称加密来保护 JS 前端和 PHP 后端之间的通信。我正在客户端上创建一个对称密钥,并使用服务器的公钥和 JSEncrypt 对其进行加密,然后将其发送到服务器以供将来使用。但是,当我在服务器端获取数据时,我遇到了困难。openssl_open 需要一个信封来解密对称密钥,我什至不确定信封中应该包含什么数据。我的印象是信封是用公钥加密的对称密钥,但使用它并没有起作用。我还尝试了不同的解码组合,因为我读到 JSEncrypt 以 64 进制编码消息,以十六进制编码密钥,但这些尝试也是徒劳的。
\n\nJS加密代码:
\n\nlet pub = "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----";\n\n//I have a function that just creates a random string of characters\nlet key = generateKey(32);\nlet aesData = CryptoJS.AES.encrypt( "test", key );\nlet symKey = aesData.key + ":::" + aesData.iv;\nlet msg = aesData.toString();\n\nlet rsa = new JSEncrypt();\nrsa.setPublicKey( pub );\nlet cryptKey = rsa.encrypt( symKey );\n\n//I\'m passing the data through a hidden form field\n$("#key").val(cryptKey + ":::" + msg);\nRun Code Online (Sandbox Code Playgroud)\n\nPHP解密代码:
\n\n$key …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码片段来加密文本PHP7:
$plaintext = "message to be encrypted";
$cipher = "aes-256-cbc";
$ivlen = openssl_cipher_iv_length($cipher);
$iv = "0123456789012345";
$key = "akshayakshayaksh";
$ciphertext = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv);
print $ciphertext;
Run Code Online (Sandbox Code Playgroud)
输出:cUXDhOEGz19QEo9XDvMzXkGFmg/YQUnXEqKVpfYtUGo=
现在,当我尝试在其中解密Python3它时,会出现错误:
from Crypto.Cipher import AES
obj2 = AES.new('akshayakshayaksh', AES.MODE_CBC, '0123456789012345')
ciphertext = "cUXDhOEGz19QEo9XDvMzXkGFmg/YQUnXEqKVpfYtUGo="
obj2.decrypt(ciphertext)
Run Code Online (Sandbox Code Playgroud)
回溯(最近一次调用):
文件“<stdin>”,第 1 行,<module>
文件“/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/blockalgo.py”,第 295 行,在解密返回 self._cipher.decrypt(ciphertext) ValueError:输入字符串的长度必须是 16 的倍数
我知道 AES 是一种分组密码算法。但是,我应该如何修复我的 PHP 代码,以便它生成“填充”密码,任何线索?
我开始使用 PHP 的openssl_encrypt方法。第二个参数是加密模式。我在哪里可以找到所有可能的方法/模式的列表?
我有一个加密方法mycrypt和密码是3des,模式ecb:
mcrypt_module_open ( MCRYPT_3DES, '', 'ecb', '' )
Run Code Online (Sandbox Code Playgroud)
现在我想使用加密它openssl_encrypt,我没有des3-ecb在openssl_get_cipher_methods()列表中找到.
我收到以下错误:
调用 Encrypter.php 第 73 行中未定义的函数 openssl_encrypt()
这看起来似乎很明显,但是在我的配置中启用了 OpenSSL 扩展,只有在使用时才会发生此错误artisan serve,查看配置并启用它。
artisan做了一些研究:在文件中复制了以下代码
$loaded = extension_loaded('openssl');
var_dump($loaded);die();
Run Code Online (Sandbox Code Playgroud)
它回来了true。但是当我将相同的代码复制到/public/index.php其中时,它会返回false.
所以我假设openssl扩展在 中启用php-cli,但由于某种原因它在到达引导文件后被禁用。
*如果有人感兴趣的话我正在使用 UniServer。
下面的代码是一个简单的.NET代码段,test在输入上它p+cTm2VODfvQnreAl02wUQ==作为输出返回.
Dim aesEncryptObj As New System.Security.Cryptography.RijndaelManaged()
Dim encoder As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding()
Dim tempKey As Byte() = encoder.GetBytes("00000011111111111111111111111111")
aesEncryptObj.Key = tempKey
aesEncryptObj.BlockSize = 128
aesEncryptObj.Mode = System.Security.Cryptography.CipherMode.ECB
aesEncryptObj.Padding = System.Security.Cryptography.PaddingMode.PKCS7
aesEncryptObj.GenerateIV()
Dim EncryptedBytes As Byte()
Dim encryptor As System.Security.Cryptography.ICryptoTransform = aesEncryptObj.CreateEncryptor(aesEncryptObj.Key, aesEncryptObj.IV)
Using msEncrypt As New System.IO.MemoryStream()
Using csEncrypt As New System.Security.Cryptography.CryptoStream(msEncrypt, encryptor, System.Security.Cryptography.CryptoStreamMode.Write)
Using swEncrypt As New System.IO.StreamWriter(csEncrypt)
swEncrypt.Write(txtInput.Text)
End Using
EncryptedBytes = msEncrypt.ToArray()
End Using
End Using
txtOutput.Text = Convert.ToBase64String(EncryptedBytes)
Run Code Online (Sandbox Code Playgroud)
现在,这是PHP代码:
const ENCRYPT_METHOD …Run Code Online (Sandbox Code Playgroud) 我在本地使用PHPMailer以及Apache和PHP。当我测试我的SSL配置和我的证书时,我得到了
default_cert_file = C:\Program Files\Common Files\SSL/cert.pem
default_cert_file_env = SSL_CERT_FILE
default_cert_dir = C:\Program Files\Common Files\SSL/certs
default_cert_dir_env = SSL_CERT_DIR
default_private_dir = C:\Program Files\Common Files\SSL/private
default_default_cert_area = C:\Program Files\Common Files\SSL
ini_cafile =
ini_capath =
Run Code Online (Sandbox Code Playgroud)
然后,我做
var_dump(fsockopen("smtp.gmail.com", 465, $errno, $errstr, 3.0));
var_dump($errno);
var_dump($errstr);
Run Code Online (Sandbox Code Playgroud)
我得到
fsockopen resource(2) of type (stream) int(0) string(0) ""
Run Code Online (Sandbox Code Playgroud)
在我的php.ini我curl.cainfo = C:/php/cacert.pem的curl一部分,它的工作原理。
但是当我尝试使用PHPMailer从本地主机发送邮件时,我不断
SSL operation failed with code 1. OpenSSL Error messages:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Failed to enable crypto
unable to connect to ssl://smtp.gmail.com:465 (Unknown …Run Code Online (Sandbox Code Playgroud) 按照这个页面的说明(下面的链接),我仍然无法安装作曲家,我不知道我在这里失败了.有没有好眼睛发现我的错误?我很亲密,我能感觉到它但没有运气,这可能是我在这里做的一个简单的错误...请帮忙!
https://getcomposer.org/download/
步骤1:
curl -sS https://getcomposer.org/installer | php
Run Code Online (Sandbox Code Playgroud)
控制台响应:
#!/usr/bin/env php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:
The openssl extension is missing, which means that secure HTTPS transfers are impossible.
If possible you should enable it or recompile php with --with-openssl
Run Code Online (Sandbox Code Playgroud)
第2步:
<?php phpinfo(); ?>
Run Code Online (Sandbox Code Playgroud)
响应:
Apache Version
Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.1e DAV/2 PHP/5.4.15
Additional .ini files parsed
/opt/local/var/db/php54/openssl.ini,
OpenSSL support …Run Code Online (Sandbox Code Playgroud) 当尝试smtp.google.com通过PHPMailer在Windows 10上由IIS托管的PHP上发送电子邮件时,我收到以下错误消息:
Connection failed.
Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages
error:14090086
SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Run Code Online (Sandbox Code Playgroud)
我确定该错误的关键部分是证书验证失败.我正在运行OpenSSL,它已启用并链接到我的PHP.这是我的本地PHP实例输出的一些信息:
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.1p 9 Jul 2015
OpenSSL Header Version => OpenSSL 1.0.1p 9 Jul 2015
Directive => Local Value => Master Value
openssl.cafile => no value => no value
openssl.capath => no value => no value
Run Code Online (Sandbox Code Playgroud)
这是我的PHP代码:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php'; …Run Code Online (Sandbox Code Playgroud) php-openssl ×12
php ×11
encryption ×5
phpmailer ×2
ssl ×2
.net ×1
aes ×1
composer-php ×1
cryptography ×1
cryptojs ×1
ecb ×1
https ×1
iis ×1
jsencrypt ×1
laravel ×1
laravel-5.3 ×1
macos ×1
macports ×1
openssl ×1
padding ×1
php-7.1 ×1
pycrypto ×1
python ×1
tcpdf ×1