PHP 8.4.2 Released!

OpenSSLAsymmetricKey 类

(PHP 8)

简介

从 PHP 8.0.0 开始替换 OpenSSL key 资源的完全不透明类。

类摘要

final class OpenSSLAsymmetricKey {
}
添加备注

用户贡献的备注 1 note

up
2
kaiserwaseem at gmail dot com
1 year ago
<?php

$data
="Your secret data goes here...";
$encrypted_data = "";

//Sample Public Key in your pem file:
$publicKey='-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoKQH6XtTUYPSIWPjtcA3I6VBF3F3TZMd9RImq0YG55qGIJvOOP0MeVib
D7MFtN4hv6ke3NyYaaUfRaxQ6mrDGzd
YOzdkqebjUzSNnwd8eQCRL2rvOsgUhf2yghLBlxq+9yfpzDV3KQ58JkCqvV1trBt/ISjPtgbK24V3v55z+cN558DMgyQmV
8pYrTFzktFVlJP20DR08HzIGimlWq/ixUfY4K
rznqapnKMw1u6SVVgGem67LC8HO9Mfx3KDseJaG7oUbSWq8vaTW2ewjEfs5JRt1OMUol7CHHtqVprcMizclqCO9Kh
Dmpussq19l0LbKbGkC73uK0Nm8RyfGhiWCQIDAQAB
-----END PUBLIC KEY-----'
;

//following line will return the object of OpenSSLAsymmetricKey
$oOpenSSLAsymmetricKey = openssl_get_publickey($publicKey);

//following line will return the encrypted data with RSA 2048 encryption
$encryptedData = openssl_public_encrypt(
$data,
$encrypted_data,
$oOpenSSLAsymmetricKey,
OPENSSL_SSLV23_PADDING
);

var_dump($encrypted_data);
To Top