|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-11-16 13:38 UTC] albertcasademont at gmail dot com
[2015-12-03 23:17 UTC] bukka@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: bukka
[2015-12-03 23:25 UTC] bukka@php.net
[2015-12-04 18:57 UTC] lagrange dot louis at gmail dot com
[2015-12-04 19:15 UTC] bukka@php.net
[2015-12-04 20:48 UTC] lagrange dot louis at gmail dot com
[2016-02-06 01:21 UTC] mcastelluccio at mozilla dot com
[2016-03-02 15:01 UTC] albertcasademont at gmail dot com
[2016-03-02 15:50 UTC] florent at morselli dot fr
[2016-04-28 14:02 UTC] florent at morselli dot fr
[2016-06-19 17:10 UTC] bukka@php.net
-Status: Assigned
+Status: Closed
[2016-06-19 17:10 UTC] bukka@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 17:00:01 2025 UTC |
Description: ------------ While the gcm mode (which is authenticated encryption) is reported in openssl_get_cipher_methods() (e.g. [106] => aes-256-gcm), neither openssl_encrypt nor openssl_decrypt support it. There simply is no code to supply/return the authentication tag. It should be fairly simple to add however it possibly requires a change of the return type, because ciphertext and tag need to be returned in the encryption case and ciphertext and tag need to be supplied for decryption. It should also be possible to distinguish between decryption failure due to authentication failure vs. other failure. The code below *should*, as last line, print 'recovered: Hello World', however decryption with gcm always fails. Test script: --------------- echo print_r(openssl_get_cipher_methods(), true); $cipher = 'aes-256-gcm'; $ivlen = openssl_cipher_iv_length($cipher); echo "iv len: " . $ivlen . "\n"; $iv = openssl_random_pseudo_bytes($ivlen); $hexiv = bin2hex($iv); echo "iv: " . $hexiv . "\n"; $plaintext = "Hello World"; echo "plaintext: " . $plaintext . "\n"; $clearpass = 'passphrase'; $pbkdfsalt = openssl_random_pseudo_bytes(16); $password = hash_pbkdf2('sha256', $clearpass, $pbkdfsalt, 1001, 32, true); echo "clearpass: " . $clearpass . "\n"; echo "pbkdfsalt: " . bin2hex($pbkdfsalt) . "\n"; echo "password: " . bin2hex($password) . "\n"; // This is the important part: $ciphertext = openssl_encrypt($plaintext, $cipher, $password, 0, $iv); echo "ciphertext: " . print_r($ciphertext, true) . "\n"; $recovered = openssl_decrypt($ciphertext, $cipher, $password, 0, $iv); echo "recovered: " . $recovered . "\n";