phpday 2025 - Call For Papers

Класс OpenSSLAsymmetricKey

(PHP 8)

Введение

Полностью непрозрачный класс, заменяющий ресурсы OpenSSL key в PHP 8.0.0.

Обзор класса

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