OpenSSL 函数 业 ,精于勤 荒于嬉.
- OpenSSL 函数 openssl_get_curve_names 获得ECC的可用曲线名称列表
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
1
<?php
2
$curve_names
= openssl_get_curve_names();
3
print_r(
$curve_names
);
4
?>
- OpenSSL 函数 openssl_get_md_methods 获取可用的摘要算法
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
1
<?php
2
$digests
= openssl_get_md_methods();
3
$digests_and_aliases
= openssl_get_md_methods(true);
4
$digest_aliases
=
array_diff
(
$digests_and_aliases
,
$digests
);
5
print_r(
$digests
);
6
print_r(
$digest_aliases
);
7
?>
- OpenSSL 函数 openssl_get_privatekey 别名 openssl_pkey_get_private()
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
openssl_get_privatekey
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
openssl_get_privatekey — 别名 openssl_pkey_get_private()
说明
此函数是该函数的别名: openssl_pkey_get_private().
- OpenSSL 函数 openssl_get_publickey 别名 openssl_pkey_get_public()
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
openssl_get_publickey
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
openssl_get_publickey — 别名 openssl_pkey_get_public()
说明
此函数是该函数的别名: openssl_pkey_get_public().
- OpenSSL 函数 openssl_open 打开密封的数据
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
01
<?php
02
// $sealed and $env_key are assumed to contain the sealed data// and our envelope key, both given to us by the sealer.// fetch private key from file and ready it$fp = fopen("/src/openssl-0.9.6/demos/sign/key.pem", "r");
03
$priv_key
=
fread
(
$fp
, 8192);
04
fclose(
$fp
);
05
$pkeyid
= openssl_get_privatekey(
$priv_key
);
06
// decrypt the data and store it in $openif (openssl_open($sealed, $open, $env_key, $pkeyid)) {
07
echo
"here is the opened data: "
,
$open
;
08
}
09
else
{
10
echo
"failed to open data"
;
11
}
12
// free the private key from memoryopenssl_free_key($pkeyid);
13
?>
- OpenSSL 函数 openssl_pbkdf2 生成一个 PKCS5 v2 PBKDF2 字符串
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
1
<?php
2
$password
=
'yOuR-pAs5w0rd-hERe'
;
3
$salt
= openssl_random_pseudo_bytes(12);
4
$keyLength
= 40;
5
$iterations
= 10000;
6
$generated_key
= openssl_pbkdf2(
$password
,
$salt
,
$keyLength
,
$iterations
,
'sha256'
);
7
echo
bin2hex(
$generated_key
).
"\n"
;
8
echo
base64_encode
(
$generated_key
).
"\n"
;
9
?>
- OpenSSL 函数 openssl_pkcs12_export_to_file 输出一个 PKCS#12 兼容的证书存储文件
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
openssl_pkcs12_export_to_file
(PHP 5 >= 5.2.2, PHP 7, PHP 8)
openssl_pkcs12_export_to_file — 输出一个 PKCS#12 兼容的证书存储文件
说明
openssl_pkcs12_export_to_file(
mixed$x509
,
string$filename
,
mixed$priv_key
,
string$pass
,
array$args
= ?
): boolopenssl_pkcs12_export_to_file() 函数以 PKCS#12 格式将
x509
保存至文件名为filename
的文件中。参数
-
x509
-
参见密钥/证书参数以获取有效值列表。
-
filename
-
输出文件的路径。
-
priv_key
-
PKCS#12文件的私钥部分。 参见 公/私钥参数 获取可用值的列表。
-
pass
-
用于解锁 PKCS#12 文件的加密密码。
-
args
-
可选数组,其他主键将被忽略。
Key 说明 "extracerts"
PKCS#12 文件中包含的额外证书或单个证书的数组。 "friendlyname"
被证书和密钥使用的字符串
返回值
成功时返回
true
, 或者在失败时返回false
。 -
- OpenSSL 函数 openssl_pkcs12_export 将 PKCS#12 兼容证书存储文件导出到变量
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
openssl_pkcs12_export
(PHP 5 >= 5.2.2, PHP 7, PHP 8)
openssl_pkcs12_export — 将 PKCS#12 兼容证书存储文件导出到变量
说明
openssl_pkcs12_export(
mixed$x509
,
string&$out
,
mixed$priv_key
,
string$pass
,
array$args
= ?
): boolopenssl_pkcs12_export() 以 PKCS#12 文件格式 将
x509
导入到以out
命名类型为字符串的变量中。参数
-
x509
-
参见密钥/证书参数以获取有效值列表。
-
out
-
成功,该字符串将为 PKCS#12 格式。
-
priv_key
-
PKCS#12 文件的私钥部分file, 参见 公/私钥参数 获取更多可用列表。
-
pass
-
用来解锁 PKCS#12 文件的解密密码。
-
args
-
可选数组,其他主键将被忽略。
Key 说明 "extracerts"
PKCS#12 文件中包含的额外证书或单个证书的数组。 "friendlyname"
被证书和密钥使用的字符串
返回值
成功时返回
true
, 或者在失败时返回false
。 -
- OpenSSL 函数 openssl_pkcs12_read 将 PKCS#12 证书存储区解析到数组中
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
01
<?php
02
if
(!
$cert_store
=
file_get_contents
(
"/certs/file.p12"
)) {
03
echo
"Error: Unable to read the cert file\n"
;
04
exit
;
05
}
06
if
(openssl_pkcs12_read(
$cert_store
,
$cert_info
,
"my_secret_pass"
)) {
07
echo
"Certificate Information\n"
;
08
print_r(
$cert_info
);
09
}
10
else
{
11
echo
"Error: Unable to read the cert store.\n"
;
12
exit
;
13
}
14
?>
- OpenSSL 函数 openssl_pkcs7_decrypt 解密一个 S/MIME 加密的消息
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
01
<?php
02
// $cert and $key are assumed to contain your personal certificate and private// key pair, and that you are the recipient of an S/MIME message$infilename = "encrypted.msg";
03
// this file holds your encrypted message$outfilename = "decrypted.msg";
04
// make sure you can write to this fileif (openssl_pkcs7_decrypt($infilename, $outfilename, $cert, $key)) {
05
echo
"decrypted!"
;
06
}
07
else
{
08
echo
"failed to decrypt!"
;
09
}
10
?>
- OpenSSL 函数 openssl_pkcs7_encrypt 加密一个 S/MIME 消息
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
01
<?php
02
// the message you want to encrypt and send to your secret agent// in the field, known as nighthawk. You have his certificate// in the file nighthawk.pem$data = <<<EODNighthawk,Top secret, for your eyes only!The enemy is closing in! Meet me at the cafe at 8.30amto collect your forged passport!HQEOD;
03
// load key$key = file_get_contents("nighthawk.pem");
04
// save message to file$fp = fopen("msg.txt", "w");
05
fwrite(
$fp
,
$data
);
06
fclose(
$fp
);
07
// encrypt itif (openssl_pkcs7_encrypt("msg.txt", "enc.txt", $key, array("To" => "nighthawk@example.com", // keyed syntax "From: HQ <hq@example.com>", // indexed syntax "Subject" => "Eyes only"))) {
08
// message encrypted - send it! exec(ini_get("sendmail_path") . " < enc.txt");
09
}
10
?>
- OpenSSL 函数 openssl_pkcs7_read 将 PKCS7 文件导出为 PEM 格式证书的数组
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
01
<?php
02
$file
=
'certs.p7b'
;
03
$f
=
file_get_contents
(
$file
);
04
$p7
=
array
();
05
$r
= openssl_pkcs7_read(
$f
,
$p7
);
06
if
(
$r
=== false) {
07
printf(
"ERROR: %s is not a proper p7b file"
.PHP_EOL,
$file
);
08
for
(
$e
= openssl_error_string(),
$i
= 0;
09
$e
;
10
$e
= openssl_error_string(),
$i
++) printf(
"SSL l%d: %s"
.PHP_EOL,
$i
,
$e
);
11
exit
(1);
12
}
13
print_r(
$p7
);
14
?>
- OpenSSL 函数 openssl_pkcs7_sign 对一个 S/MIME 消息进行签名
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
1
<?php
2
// the message you want to sign so that recipient can be sure it was you that// sent it$data = <<<EODYou have my authorization to spend $10,000 on dinner expenses.The CEOEOD;
3
// save message to file$fp = fopen("msg.txt", "w");
4
fwrite(
$fp
,
$data
);
5
fclose(
$fp
);
6
// encrypt itif (openssl_pkcs7_sign("msg.txt", "signed.txt", "file://mycert.pem", array("file://mycert.pem", "mypassphrase"), array("To" => "joes@example.com", // keyed syntax "From: HQ <ceo@example.com>", // indexed syntax "Subject" => "Eyes only") )) {
7
// message signed - send it! exec(ini_get("sendmail_path") . " < signed.txt");
8
}
9
?>
- OpenSSL 函数 openssl_pkcs7_verify 校验一个已签名的 S/MIME 消息的签名
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
openssl_pkcs7_verify
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
openssl_pkcs7_verify — 校验一个已签名的 S/MIME 消息的签名
说明
openssl_pkcs7_verify(
string$filename
,
int$flags
,
string$outfilename
= ?,
array$cainfo
= ?,
string$extracerts
= ?,
string$content
= ?,
string$p7bfilename
= ?
): mixedopenssl_pkcs7_verify() 读取给定文件中的 S/MIME 消息并且检查数字签名。
参数
-
filename
-
消息的路径。
-
flags
-
flags
可以用来影响如何校验签名 - 参见 PKCS7 常量 获取更多信息。 -
outfilename
-
如果已指定
outfilename
输出文件,它应该是一个用以保存文件的字符串名称,签名消息的个人证书将以 PEM 的格式保存起来。 -
cainfo
-
如果
cainfo
被指定了,它应该保存关于受信任的CA证书的信息供在验证过程中使用 - 参见 证书校验 获取关于该参数的更多信息。 -
extracerts
-
如果
extracerts
被指定了,该文件包含了一堆会被作为不受信任的ca使用的证书。 -
content
-
你可以使用
content
来指定带有已被验证数据的文件名,该文件内容已去掉了签名信息。 -
p7bfilename
-
返回值
如果签名已被认证,返回
true
, 如果不正确 (消息已被篡改或者签名证书不可用) 则返回false
, 或者 - 错误时返回1.更新日志
版本 说明 7.2.0 新增 p7bfilename
参数。注释
注意: 正如 RFC 2045 中指定的,
filename
参数最多不可超过 76 个字符串。 -
- OpenSSL 函数 openssl_pkey_derive Computes shared secret for public value of remote and local DH or ECDH key
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
示例1
1
<?php
2
// Load in private key$priv = openssl_pkey_get_private("-----BEGIN PRIVATE KEY-----MIICJgIBADCCARcGCSqGSIb3DQEDATCCAQgCggEBAJLxRCaZ933uW+AXmabHFDDyupojBIRlbmQLJZfigDaSA1f9YOTsIv+WwVFTX/J1mtCyx9uBcz0Nt2kmVwxWuc2fVtCEMPsmLsVXX7xRUFLpyX1Y1IYGBVXQOoOvLWYQjpZgnx47Pkh1Ok1+smffztfC0DCNt4KorWrbsPcmqBejXHN79KvWFjZmXOksRiNu/Bn76RiqvofC4z8Ri3kHXQG2197JGZzzFXHadGC3xbkg8UxsNbYhVMKbm0iANfafUH7/hoS9UjAVQYtvwe7YNiW/HnyfVCrKwcc7sadd8Iphh+3lf5P1AhaQEAMytanrzq9RDXKBxuvpSJifRYasZYsCAQIEggEEAoIBAGwAYC2E81Y1U2Aox0U7u1+vBcbht/OO87tutMvc4NTLf6NLPHsWcPqBixs+3rSn4fADzAIvdLBmogjtiIZoB6qyHrllF/2xwTVGEeYaZIupQH3bMK2b6eUvnpuu4Ytksiz6VpXBBRMrIsj3frM+zUtnq8vKUr+TbjV2qyKR8l3eNDwzqz30dlbKh9kIhZafclHfRVfyp+fVSKPfgrRAcLUgAbsVjOjPeJ90xQ4DTMZ6vjiv6tHMhkSjJIcGhRtSBzVF/cT38GyCeTmiIA/dRz2d70lWrqDQCdp9ArijgnpjNKAAulSYCirnMsGZTDGmLOHg4xOZ5FEAzZI2sFNLlcw=-----END PRIVATE KEY-----");
3
// Load in public key$pub = openssl_pkey_get_public("-----BEGIN PUBLIC KEY-----MIICJDCCARcGCSqGSIb3DQEDATCCAQgCggEBAJLxRCaZ933uW+AXmabHFDDyupojBIRlbmQLJZfigDaSA1f9YOTsIv+WwVFTX/J1mtCyx9uBcz0Nt2kmVwxWuc2fVtCEMPsmLsVXX7xRUFLpyX1Y1IYGBVXQOoOvLWYQjpZgnx47Pkh1Ok1+smffztfC0DCNt4KorWrbsPcmqBejXHN79KvWFjZmXOksRiNu/Bn76RiqvofC4z8Ri3kHXQG2197JGZzzFXHadGC3xbkg8UxsNbYhVMKbm0iANfafUH7/hoS9UjAVQYtvwe7YNiW/HnyfVCrKwcc7sadd8Iphh+3lf5P1AhaQEAMytanrzq9RDXKBxuvpSJifRYasZYsCAQIDggEFAAKCAQAiCSBpxvGgsTorxAWtcAlSmzAJnJxFgSPef0g7OjhESytnc8G2QYmxovMt5KVergcitztWh08hZQUdAYm4rI+zMlAFDdN8LWwBT/mGKSzRkWeprd8E7mvyucqC1YXCMqmIwPySvLQUB/Dl8kgau7BLAnIJm8VP+MVrn8g9gghD0qRCgPgtEaDVvocfgnOU43rhKnIgO0cHOKtw2qybSFB8QuZrYugq4j8Bwkrzh6rdMMeyMl/ej5Ajc0wamOzuBDtXt0T9+Fx3khHaowjCc7xJZRgZCxg43SbqMWJ9lUg94I7+LTX61GyvdtlkbGbtoDOnxeNnN93gwQZngGYZYciu-----END PUBLIC KEY-----");
4
// Outputs the hex version of the derived keyecho bin2hex(openssl_pkey_derive($pub,$priv));
- OpenSSL 函数 openssl_pkey_export_to_file 将密钥导出到文件中
-
发表日期:2021-07-01 08:55:23 | 来源: | 分类:OpenSSL 函数
-
openssl_pkey_export_to_file
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
openssl_pkey_export_to_file — 将密钥导出到文件中
说明
openssl_pkey_export_to_file(
mixed$key
,
string$outfilename
,
string$passphrase
= ?,
array$configargs
= ?
): boolopenssl_pkey_export_to_file() 将 ascii 格式 (PEM编码)的
key
保存到名为outfilename
文件中。注意: 必须安装有效的 openssl.cnf 以保证此函数正确运行。参考有关安装的说明以获得更多信息。
参数
-
key
-
-
outfilename
-
输出文件的路径。
-
passphrase
-
密钥可以通过值为
passphrase
的密码来保护。 -
configargs
-
configargs
可以用来调整导出流程,通过指定或者覆盖openssl配置文件选项。参见 openssl_csr_new() 获取更多关于configargs
的信息。
返回值
成功时返回
true
, 或者在失败时返回false
。 -
- OpenSSL 函数 openssl_pkey_export 将一个密钥的可输出表示转换为字符串
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
openssl_pkey_export
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
openssl_pkey_export — 将一个密钥的可输出表示转换为字符串
说明
openssl_pkey_export(
mixed$key
,
string&$out
,
string$passphrase
= ?,
array$configargs
= ?
): boolopenssl_pkey_export() 将
key
当作 PEM 编码字符串导出并且将之保存到out
(通过引用传递的)中。注意: 必须安装有效的 openssl.cnf 以保证此函数正确运行。参考有关安装的说明以获得更多信息。
参数
-
key
-
-
out
-
-
passphrase
-
密钥可以通过
passphrase
来保护。 -
configargs
-
configargs
可以用来调整导出流程,通过指定或者覆盖openssl配置文件选项。参见 openssl_csr_new() 获取更多关于configargs
的信息。
返回值
成功时返回
true
, 或者在失败时返回false
。 -
- OpenSSL 函数 openssl_pkey_free 释放一个私钥
-
发表日期:2021-07-01 08:55:22 | 来源: | 分类:OpenSSL 函数
-
openssl_pkey_free
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
openssl_pkey_free — 释放一个私钥
参数
-
key
-
持有该密钥的资源。
返回值
没有返回值。
-
- OpenSSL 函数 openssl_pkey_get_details 返回包含密钥详情的数组
-
发表日期:2021-07-01 08:55:23 | 来源: | 分类:OpenSSL 函数
-
openssl_pkey_get_details
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
openssl_pkey_get_details — 返回包含密钥详情的数组
说明
openssl_pkey_get_details(resource$key
): array该函数返回密钥详情(位长度,密钥,类型).
参数
-
key
-
持有密钥的资源。
返回值
成功,返回包含密钥详情的数组,失败返回
false
. 返回的数组中包含了如下索引:bits
(位数),key
(表示公钥的字符串) 和type
(如下密钥类型之一:OPENSSL_KEYTYPE_RSA
,OPENSSL_KEYTYPE_DSA
,OPENSSL_KEYTYPE_DH
,OPENSSL_KEYTYPE_EC
或者 未知类型返回1).取决于所使用密钥的类型,可能会返回其他额外的信息。请注意,有些元素可能并不总是可用的。
-
OPENSSL_KEYTYPE_RSA
, 一个额外的键名为"rsa"
的数组,包含了以下密钥数据:Key 说明 "n"
modulus "e"
public exponent "d"
private exponent "p"
prime 1 "q"
prime 2 "dmp1"
exponent1, d mod (p-1) "dmq1"
exponent2, d mod (q-1) "iqmp"
coefficient, (inverse of q) mod p -
OPENSSL_KEYTYPE_DSA
, 一个额外的键为"dsa"
的数组, 包含如下的密钥数据。Key 说明 "p"
prime number (public) "q"
160-bit subprime, q | p-1 (public) "g"
generator of subgroup (public) "priv_key"
private key x "pub_key"
public key y = g^x -
OPENSSL_KEYTYPE_DH
, 一个额外的键为"dh"
的数组,包含如下的密钥数据。Key 说明 "p"
prime number (shared) "g"
generator of Z_p (shared) "priv_key"
private DH value x "pub_key"
public DH value g^x -
OPENSSL_KEYTYPE_EC
, 一个额外的键为"ec"
的数组,包含如下的密钥数据。Key 说明 "curve_name"
name of curve, see openssl_get_curve_names() "curve_oid"
ASN1 Object identifier (OID) for EC curve. "x"
x coordinate (public) "y"
y coordinate (public) "d"
private key
-
- OpenSSL 函数 openssl_pkey_get_private 获取私钥
-
发表日期:2021-07-01 08:55:23 | 来源: | 分类:OpenSSL 函数
-
openssl_pkey_get_private
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
openssl_pkey_get_private — 获取私钥
说明
openssl_pkey_get_private(mixed$key
, string$passphrase
= ""): resourceopenssl_get_privatekey() 解析
key
供其他函数使用。参数
-
key
-
key
可以是如下密钥之一:- 如下格式的字符串 file://path/to/file.pem。该文件必须包含 PEM 编码的证书或者私钥 (可能都包含了).
- 一个PEM格式的私钥。
-
passphrase
-
如果指定的密钥已被加密了(受密码保护),可选参数
passphrase
是必须要的。
返回值
成功,返回真实的密钥资源标识符,失败,返回
false
. -
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)