# Encrypt/Decrypt AES256 - (Security::encrypt((string)$value, $key);

**URL:** <https://discourse.cakephp.org/t/encrypt-decrypt-aes256-security-encrypt-string-value-key/10172>\
**Category:** Need Help\
**Created:** [February 18, 2022, 10:54am UTC](https://discourse.cakephp.org/t/encrypt-decrypt-aes256-security-encrypt-string-value-key/10172 "2022-02-18T10:54:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dolando](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@Dolando](https://discourse.cakephp.org/u/Dolando)\
**Post date:** [February 18, 2022, 10:54am UTC](https://discourse.cakephp.org/t/encrypt-decrypt-aes256-security-encrypt-string-value-key/10172/1 "2022-02-18T10:54:03Z")

</div>

I write Cookies as mentioned above - encrypted with Security::encrypt.  
$key is what I get with Security::getSalt();  
Does anybody know how to decrypt in plain PHP?  
I have a PHP-Script that should read and write cookies from my Cake application.  
There are different versions of AES256.  
I am using Cake 4.2.3.

Thanks for helping me.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 18, 2022, 2:20pm UTC](https://discourse.cakephp.org/t/encrypt-decrypt-aes256-security-encrypt-string-value-key/10172/2 "2022-02-18T14:20:50Z")

</div>

What function are you using to encrypt them?

Have you seen then [encrypted cookie middleware](https://book.cakephp.org/4/en/controllers/middleware.html#encrypted-cookie-middleware)?
