The OpenSSLAsymmetricKey class

(PHP 8)

Introduzione

A fully opaque class which replaces OpenSSL key resources as of PHP 8.0.0.

Sommario della classe

final class OpenSSLAsymmetricKey {
}
add a note

User Contributed Notes 1 note

up
1
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