PHPのお勉強!

PHP TOP

OpenSSLAsymmetricKey クラス

(PHP 8)

はじめに

PHP 8.0.0 以降、 OpenSSL key リソースを置き換える完全不透明クラスです。

クラス概要

final class OpenSSLAsymmetricKey {
}
add a note

User Contributed Notes 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