diff --git a/docs/Compatibility.md b/docs/Compatibility.md index a0a6c400..61568ca9 100644 --- a/docs/Compatibility.md +++ b/docs/Compatibility.md @@ -6,6 +6,7 @@ Here’s how to decrypt in other languages. For files, skip Base64 decoding the - [Python](#python) - [Rust](#rust) - [Elixir](#elixir) +- [PHP](#php) Pull requests are welcome for other languages. @@ -87,3 +88,19 @@ ciphertext_size = byte_size(ciphertext) - 28 :crypto.block_decrypt(:aes_gcm, key, nonce, {"", ciphertext, tag}) ``` + +## PHP + +```php +$ciphertext = "Uv/+Sgar0kM216AvVlBH5Gt8vIwtQGfPysl539WY2DER62AoJg=="; +$key = "61e6ba4a3a2498e3a8fdcd047eff0cd9864016f2c83c34599a3257a57ce6f7fb"; + +$key = hex2bin($key); + +$ciphertext = base64_decode($ciphertext, true); +$nonce = substr($ciphertext, 0, 12); +$tag = substr($ciphertext, -16); +$ciphertext = substr($ciphertext, 12, -16); + +$plaintext = openssl_decrypt($ciphertext, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $nonce, $tag); +``` \ No newline at end of file