assistenzde/simple-cryptographic-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

assistenzde/simple-cryptographic-bundle

Composer 安装命令:

composer require assistenzde/simple-cryptographic-bundle

包简介

A simple cryptographic service to encode/decode an input string with openssl_encrypt methods like aes128, aes256, blowfish and other cipher methods.

关键字:

README 文档

README

Latest Stable Version Total Downloads License PHP ≥v7.4 Symfony ≥5

The SimpleCryptographicService class contains method to encrypt/decrypt phrases with symmetric encryption. With the usage of OpenSSL each encoding of the same phrase results in a different encoded string.

Quick example usage:

$cryptographicService = new SimpleCryptographicService('$ecr3t');

$encryptedString1 = $cryptographicService->encrypt('Hello world!');  // some encrypted string, i.e. 'ABCDEFG'
echo $cryptographicService->decrypt($encryptedString1);              // outputs 'Hello world!'

$encryptedString2 = $cryptographicService->encrypt('Hello world!');  // some encrypted string, i.e. 'HIJKLMNOP'
echo $cryptographicService->decrypt($encryptedString2);              // outputs 'Hello world!'

This library can be used easily in Symfony projects but also in non-Symfony projects.

Table of Contents

Requirements

The usage of PHP ≥ v7.4 and Symfony ≥ 5 is recommended.

Installation

Please install via composer.

composer require assistenzde/simple-cryptographic-bundle

The bundle will be automatically added to your bundles.yaml configuration.

Symfony Configuration

By default the bundle depends on the APP_SECRET environment variable and uses the aes-256-ctr cipher method. If you want to use a custom cipher key OR a customer cipher method create the config/packates/simple-cryptographic-bundle.yaml configuration file and set the related values.

simple-cryptographic-bundle.yaml:

simple-cryptographic-bundle.yaml:
  # set a custom cipher key or comment out to use the default value
  # default is %kernel.secret% (which contains the APP_SECRET value)
  key: My-cu5t0m-c1ph3r-k3y
  # set a custom cipher method or comment out to use the default value
  # default is aes-256-ctr
  cipher: camellia-128-ofb

Usage

Use dependency injection to access the cryptographic service.

<?php

namespace MyNamespace;

use Assistenzde\SimpleCryptographicBundle\Service\SimpleCryptographicService;

/**
 * Class AuthenticationSubscriber
 */
final class MyClass
{
    /**
     * the crypto service to encode/dedoce strings
     * 
     * @var SimpleCryptographicService
     */
    protected SimpleCryptographicService $simpleCryptographicService;

    /**
     * MyClass constructor
     * 
     * @param SimpleCryptographicService $simpleCryptographicService
     */
    public function __construct(SimpleCryptographicService $simpleCryptographicService)
    {       
        $this->simpleCryptographicService = $simpleCryptographicService;
    }

    /**
     * 
     */
    public function doSomething()
    {       
         // do some calculation and get a user token
         
         // encrypt the user token        
         $encryptedUserToken = $this->simpleCryptographicService->encrypt($userToken);
         
         // and do some more stuff,
         // esp. use the encrypted token (i.e. as request parameter or to save in a file)

         // derypt the encrypted stuff        
         $userToken = $this->simpleCryptographicService->decrypt($encryptedUserToken); 
    }
}

We suggest using the public methods

  • SimpleCryptographicService::encrypt and
  • SimpleCryptographicService::decrypt.

To temporarily use custom settings switch to the static methods

  • SimpleCryptographicService::EncryptWithMethod and/or
  • SimpleCryptographicService::DecryptWithMethod.

Credits

A big thank you to stackoverflow's user Scott Arciszewski for the explanations in of the https://stackoverflow.com/a/30189841/4351778 answer.

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固