PHPackages                             larryphp/encryption - 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. [Security](/categories/security)
4. /
5. larryphp/encryption

ActiveLibrary[Security](/categories/security)

larryphp/encryption
===================

A tiny encryptor from Laravel.

1.0.2(8y ago)31.7k↓50%1MITPHPPHP &gt;=5.4

Since Mar 12Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Lofanmi/encryption)[ Packagist](https://packagist.org/packages/larryphp/encryption)[ RSS](/packages/larryphp-encryption/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

LarryPHP Encryption
===================

[](#larryphp-encryption)

[中文](https://github.com/Lofanmi/encryption/blob/master/README_zh-CN.md)

Thank you for choosing LarryPHP Encryption - a tiny encryptor from Laravel, for doing encryption in PHP.

[![StyleCI](https://camo.githubusercontent.com/4846b5e700699e4e4e7d0111dee540980c6ac109bbba7d5db423088181e5c260/68747470733a2f2f7374796c6563692e696f2f7265706f732f35333636323833312f736869656c643f7374796c653d666c6174266272616e63683d6d6173746572)](https://styleci.io/repos/53662831)[![Build Status](https://camo.githubusercontent.com/9b97df8b4fc05894ba779870a7f97b38daed704b533774e0c93bbebc56cdc95e/68747470733a2f2f7472617669732d63692e6f72672f4c6f66616e6d692f656e6372797074696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Lofanmi/encryption)[![codecov.io](https://camo.githubusercontent.com/93dccb2b9680a7164623743e55884cf9b8007c02cfdeda577a274985b46abc61/687474703a2f2f636f6465636f762e696f2f6769746875622f4c6f66616e6d692f656e6372797074696f6e2f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/Lofanmi/encryption?branch=master)[![Total Downloads](https://camo.githubusercontent.com/aef2101e45d4794cb0f8e52220bd9eb0d779a39e869e08db3f2c01c4cfa92a8b/68747470733a2f2f706f7365722e707567782e6f72672f6c617272797068702f656e6372797074696f6e2f646f776e6c6f616473)](https://packagist.org/packages/larryphp/encryption)[![Latest Stable Version](https://camo.githubusercontent.com/ef7faf2c8159726858e647920a075e6d324d5ee2301c78a660e29c5569461513/68747470733a2f2f706f7365722e707567782e6f72672f6c617272797068702f656e6372797074696f6e2f762f737461626c65)](https://packagist.org/packages/larryphp/encryption)[![Latest Unstable Version](https://camo.githubusercontent.com/9abd13f83303000b9477cc6d5519771ab11029d0095f152487b32e18f935edcb/68747470733a2f2f706f7365722e707567782e6f72672f6c617272797068702f656e6372797074696f6e2f762f756e737461626c65)](https://packagist.org/packages/larryphp/encryption)[![License](https://camo.githubusercontent.com/1f691e4676b4ccc3c6d5f0e288d67817559557b966976398350e00b98c66bfb3/68747470733a2f2f706f7365722e707567782e6f72672f6c617272797068702f656e6372797074696f6e2f6c6963656e7365)](https://packagist.org/packages/larryphp/encryption)

Requirements
------------

[](#requirements)

The minimum requirement is that your Web server supports PHP 5.4.

Implementation
--------------

[](#implementation)

Messages are encrypted with AES-128/256 in CBC mode and are authenticated with HMAC-SHA256 (Encrypt-then-Mac). It is implemented using the `openssl_` and `hash_hmac` functions, compatible with Laravel Encryption.

For URL application or Filenames, you can use the helper function `larryphp_encrypt_url` which makes a replacement from `['+', '/', '=']` to `['-', '_', '']`. Don't forget to use `larryphp_decrypt_url` to decrypt the payload.

See wikipedia for more infomation [Base64](https://en.wikipedia.org/wiki/Base64#RFC_3548).

> Using standard Base64 in URL requires encoding of '+', '/' and '=' characters into special percent-encoded hexadecimal sequences ('+' becomes '%2B', '/' becomes '%2F' and '=' becomes '%3D'), which makes the string unnecessarily longer.

> Another variant called modified Base64 for filename uses '-' instead of '/', because Unix and Windows filenames cannot contain '/'.

> It could be recommended to use the modified Base64 for URL instead, since then the filenames could be used in URLs also.

> For this reason, modified Base64 for URL variants exist, where the '+' and '/' characters of standard Base64 are respectively replaced by '-' and '\_', so that using URL encoders/decoders is no longer necessary and have no impact on the length of the encoded value, leaving the same encoded form intact for use in relational databases, web forms, and object identifiers in general. Some variants allow or require omitting the padding '=' signs to avoid them being confused with field separators, or require that any such padding be percent-encoded. Some libraries (like org.bouncycastle.util.encoders.UrlBase64Encoder) will encode '=' to '.'.

Install
-------

[](#install)

To install with composer:

```
composer require larryphp/encryption
```

Usage
-----

[](#usage)

```
