PHP АСИММЕТРИЧНОЕ ШИФРОВАНИЕ

Asymmetric encryption is a cryptographic approach that uses two different keys for encryption and decryption. One key is called the public key, which is widely distributed, and the other is the private key, which is kept secret.

PHP has built-in functions for asymmetric encryption, including openssl_public_encrypt, openssl_private_decrypt, openssl_public_decrypt and openssl_private_encrypt.

For example, to encrypt a message using a public key, you can use the openssl_public_encrypt() function:

$publicKey = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCfzYW5o9kUG/QLHK9Kz3tRHTDX\n3uN+XsM7dIgZojM9/XsNTB5Dl7wIcpLyUXrRHuoYTxTlYk+5OzTuoApP5nghgp49\n5e1UXFfC5FTe/b1nte2/5PqVCIHQIRjjDhtqlHvRlLR3ZHKLW/PpgLxwgj+VdJg/\nyp0LvRUvOQyWYN/3KwIDAQAB\n-----END PUBLIC KEY-----";
$message = "Hello World";
openssl_public_encrypt($message, $encrypted, $publicKey);

To decrypt the message using the corresponding private key, you can use the openssl_private_decrypt() function as follows:

$privateKey = "-----BEGIN PRIVATE KEY-----\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJ/Nhbmj2RQb9Ask\ncr0rPe1EdMNfe435ewzt0iBmijM383w1ME5e8CHKS8lF60R7qGE8U5WJPuTs07qA\nKT+Z4IYKePeeLVcUV8LkVN79vWd17b/k+pUIgdAhGOMOG2qUe9GUtHdkcotb8+mA\nvHCCP5V0mD/KnQu9FS85DJZg3/crAgMBAAECgYA5eyKj6NLxxpHTj6rQ7NliPpG6\nX6w7Y0X0b5Z+KbUxQfi9nnR+i8POGaz6DmnXGjU6b9eKM0F/IeNXBZ47kQrO2fPd\n8P4L6nh8Xb/HJA6lItVPiqGJL+sjYbrKcQ/3KOKo5W/IOh1Mg0yGgWK2fOY/sGBj\nmKho1iG/Ng7j5/hDAQJBAO469O4HUW/BloVvdjvVFGeeZ+3esTHBvyOSejDxRkCC\ntQkReFMjEdwdxqlNRV49/gc9cYVfN6LkBevg7bJUOVMCQQDO4JMQ1hlRZJQ5j+lt\nFzwNXrX9FkYRAiFqnIVrQr3Qd39/oEDl8ljrKv1tY9/XQDCMSvhR9G9ysM5wEn+v\nBIfVAkEAiOqSSbz3gcYbDGK7F/tO7p4H1vRnzNNuDCmjyzxfpvEn49BZlCCx/IU0\nWEZ6L9TpU2g7BAqb3iI8zZV9/KeB7wJAcIlc3ul3JM5Hz/x7SAOYTVgATpvxb5Uk\nNGcJ+9vwtHzAIHsNcGfLWfHl3dCMLlSmIEXCJRMG8IeXV45qzxl8IQJAGx0zNLvH\nossU44ZRG2Ygl9aK0b0M7MB9NyBfb1UAc3Ev/mmt+QnVrLpJdyrUsO+fF0C/Sf/v\nya+iTg5allMq4A==\n-----END PRIVATE KEY-----";
openssl_private_decrypt($encrypted, $decrypted, $privateKey);
echo $decrypted;

The output of the above code would be:

Hello World

Алгоритм шифрования RSA

Основы Шифрования за 5 минут - Asymmetric Cryptography - #ityoutubersru

124 Шифрование паролей (ruphp.com) Изучаем php

Симметричное шифрование Асимметричное шифрование Хэш

Шифрование SSL на языке PHP

Знаете ли вы как устроена SIM-карта и как она работает?

Асимметричное шифрование, цифровая подпись, алгоритм RSA, схема Эль-Гамаля

Шифрование открытым и закрытым ключом

Реклама
Новое
Реклама