承接 crudly/encrypted 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

crudly/encrypted

Composer 安装命令:

composer require crudly/encrypted

包简介

Encryption and hashing casts for Eloquent

README 文档

README

Build Status Release License

Note This package is no longer needed for new projects as hashing is now among the native casts and encryption was there for a while already. We will probably keep it up to date for a few more years because it usually only takes bumping a version tag.

A custom cast class for Laravel Eloquent that encrypts or hashes your values. Package is small and provides just a few, simple, well tested features.

protected $casts = [
    // hashes the value when assigning to $model->password
    'password' => Password::class,

    // encrypts on write, decrypts on read
    'classified' => Encrypted::class,

    // encrypts on write, decrypts & typecasts on read
    'secret' => Encrypted::class.':integer',
];

Installation

Use composer.

$ composer require crudly/encrypted

Usage

Mark any column in your model as encrypted.

<?php

namespace App;

use Crudly\Encrypted\Encrypted;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
	protected $casts = [
		'something_secret' => Encrypted::class,
	];
}

You can work with the attribute as you normally would, but it will be encrypted on the database.

$mm = new MyModel;

$mm->someting_secret = 'classified_info';
$mm->save();

Type casting

Encryption serializes the variable and decryption unserializes it, so you get out exactly what you put in. This usually means that no type casting is needed.

But sometimes you want everything casted to some type even if you put something else in. In those cases you can specify types (all of Eloquent's default casts are supported):

<?php

namespace App;

use Crudly\Encrypted\Encrypted;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
	protected $casts = [
		'encrypted_column' => Encrypted::class,
		'an_integer' => Encrypted::class.':integer',
		'a_string' => Encrypted::class.':string',
		'decimal_with_two_places' => Encrypted::class.':decimal:2',
	];
}

Password hashing

This can also be used to hash a password upon write.

<?php

namespace App;

use Crudly\Encrypted\Password;
use Illuminate\Database\Eloquent\Model;

class MyUser extends Model
{
	protected $casts = [
		'password' => Password::class,
	];
}

This hashes the password using bcrypt. You can check a string against the hashed password using Hash facade.

$mu = new MyUser;
$mu->password = 'secret';

$mu->password; // returns a hash

Hash::check('secret', $mu->password); //returns true
Hash::check('hunter2', $mu->password); //returns false

TODO

Maybe add key and cipher customization via options, i.e. Encrypted::class.':string,AckfSECXIvnK5r28GVIWUAxmbBSjTsmF' and Encrypted::class.':string,AckfSECXIvnK5r28GVIWUAxmbBSjTsmF,AES-128-CBC'. And password hashing options.

crudly/encrypted 适用场景与选型建议

crudly/encrypted 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.86k 次下载、GitHub Stars 达 62, 最近一次更新时间为 2020 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「encryption」 「hashing」 「laravel」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 crudly/encrypted 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 crudly/encrypted 我们能提供哪些服务?
定制开发 / 二次开发

基于 crudly/encrypted 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 62
  • 点击次数: 28
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 62
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-26