Change to openssl_private_decrypt Error Handling in 8.1.27
Open
@bukka is already working on this.
Since Jan 17, 2024.
Bug
Extension: openssl
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
$res = openssl_pkey_new();
openssl_pkey_export($res, $privkey);
$pubkey = openssl_pkey_get_details($res)['key'] ?? null;
// Test String
$data = 'non-encrypted data';
// Encrypt Test String
openssl_public_encrypt($data, $encrypted_data, $pubkey, OPENSSL_PKCS1_PADDING);
// Decrypt Encrypted Test String
openssl_private_decrypt($encrypted_data, $decrypted_data, $privkey, OPENSSL_PKCS1_PADDING);
echo "Starting Data: $data".PHP_EOL;
echo "Decrypted Data: $decrypted_data".PHP_EOL;
// Decrypt Unencrypted Test String
if (!openssl_private_decrypt($data, $decrypted_unencrypted_data, $privkey, OPENSSL_PKCS1_PADDING)){
echo "Could not decrypt invalid data".PHP_EOL;
}
else {
echo "Decrypted Unencrypted Data: $decrypted_unencrypted_data" . PHP_EOL;
}
Resulted in this output:
Starting Data: non-encrypted data
Decrypted Data: non-encrypted data
Decrypted Unencrypted Data: |~�
�|{[22��E�_Mr�ѝ?�lv�D2�TrKF�_+t��Z�c)
����9���`����gP���XK
����%����RfC��u��L��$Z&��%��%�CLR�����/Z��dB��ލ���T� |��`l=��_�^m��j6�����J�UU
q�N<�v�C�S�AL?��G:
But I expected this output instead:
Starting Data: non-encrypted data
Decrypted Data: non-encrypted data
Could not decrypt invalid data
PHP Version
PHP 8.1.27
Operating System
Rocky Linux release 8.9 (Green Obsidian)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.