PHPackages                             bcrowe/cakephp-encrypted-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. bcrowe/cakephp-encrypted-type

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

bcrowe/cakephp-encrypted-type
=============================

CakePHP 4 plugin that provides application-level database encryption.

2.0.1(5y ago)84.8k↓50%2MITPHPPHP &gt;=7.2

Since Sep 8Pushed 5y ago4 watchersCompare

[ Source](https://github.com/bcrowe/cakephp-encrypted-type)[ Packagist](https://packagist.org/packages/bcrowe/cakephp-encrypted-type)[ Docs](https://github.com/bcrowe/cakephp-encrypted-type)[ RSS](/packages/bcrowe-cakephp-encrypted-type/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (8)Used By (0)

CakePHP Encrypted Type
======================

[](#cakephp-encrypted-type)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9b6820e838cca0c5e088281a86c6cb24d74767702905f44c92625578aaea4e6d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6263726f77652f63616b657068702d656e637279707465642d747970652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bcrowe/cakephp-encrypted-type)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/946c13839c52c34a17ee1aa91a572294afd41e31a4d62e5ef3d3c36a75b726ab/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6263726f77652f63616b657068702d656e637279707465642d747970652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/bcrowe/cakephp-encrypted-type)[![Coverage Status](https://camo.githubusercontent.com/cb7205b6262e0d9d690773fd1de40e9ae64866cf3f939268d4c384263ab92473/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6263726f77652f63616b657068702d656e637279707465642d747970652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bcrowe/cakephp-encrypted-type/code-structure)[![Quality Score](https://camo.githubusercontent.com/269d430277a64f3acbd20d63a173b2d2ede0de442f33cb7044c712b4ede03e5c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6263726f77652f63616b657068702d656e637279707465642d747970652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bcrowe/cakephp-encrypted-type)[![Total Downloads](https://camo.githubusercontent.com/015f7fa2e5851557ec4e88e31cd6b09272d71b38dee678ce79b1685e31f5f4ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6263726f77652f63616b657068702d656e637279707465642d747970652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bcrowe/cakephp-encrypted-type)

This plugin provides a CakePHP 4 encrypted database type for application-level encryption. Before using this plugin you may want to weigh your options between [full-disk, database-level, and application-level encryption](https://www.percona.com/blog/2016/04/08/mysql-data-at-rest-encryption/). This plugin was born out of Amazon Aurora not supporting encryption with cross region replication before [March 28, 2017](https://aws.amazon.com/blogs/aws/amazon-aurora-update-more-cross-region-cross-account-support-t2-small-db-instances-another-region/).

Install
-------

[](#install)

Via Composer

```
$ composer require bcrowe/cakephp-encrypted-type
```

Load the plugin in your application's `bootstrap.php` file, then define the type mapping:

```
Plugin::load('BryanCrowe/EncryptedType');
Type::map('encrypted', 'BryanCrowe\EncryptedType\Database\Type\EncryptedType');
```

Make sure to have a `Encryption.key` config value in your `config/app.php` file:

```
[
    'Encryption' => [
        'key' => env('ENCRYPTION_KEY', 'defaultencryptionkeygoesrighthereyaythisisfun'),
    ],
]
```

Usage
-----

[](#usage)

**Note:** This database type expects columns to be nullable in the case of an omitted column or whenever explicitly setting a `null` value for a column.

Use `BLOB` types for columns that are to be encrypted, for example:

```
CREATE TABLE `users` (
  `id` char(36) NOT NULL DEFAULT '',
  `first_name` blob,
  `last_name` blob,
  `email` blob,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

[Map the type](https://book.cakephp.org/3.0/en/orm/database-basics.html#data-types)to a column in your Table class:

```
