GithubHelp home page GithubHelp logo

folded-php / crypt Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 44 KB

Encrypt and decrypt strings for your web app.

Home Page: https://packagist.org/packages/folded/crypt

License: MIT License

PHP 97.26% Dockerfile 2.74%
encryption decryption php

crypt's Introduction

folded/crypt

Easily encrypt and decrypt strings for your web app.

Build Status Maintainability TODOs

Summary

About

I created this library to be able to encrypt my data in a standalone way.

Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.

Features

  • Can encrypt and decrypt strings
  • Can generate a key (necessary to setup the library) from the command line

Requirements

  • PHP >= 7.4.0
  • Composer installed

Installation

1. Install the package

In your root folder, run this command:

composer require folded/crypt

2. Generate a key

One way to generate the key easily is through the command line. Run this command to get a new key:

vendor/bin/crypt generate key

You can get more information on the available option by running vendor/bin/crypt generate --help.

Another way is to call the function Folded\getEncryptionKey() from a script:

use function Folded\getEncryptionKey;

require __DIR__ . "/vendor/autoload.php";

echo getEncryptionKey();

You can add a parameter to control the type of cipher you want (currently supported: AES-128-CBC and AES-256-CBC).

3. Add the setup code

Before calling the library, add this setup code as early as possible:

use function Folded\setEncryptionKey;

setEncryptionKey("xIYrZSsCV6hx9x/Q4bka1PejU+aSaMerJQFSYr3QnTE=");

Examples

1. Encrypt a string

In this example, we will get the encrypted version of a string.

use function Folded\getEncryptedString;

$encryptedText = getEncryptedString("hello world");

2. Decrypt a string

In this example, we will decrypt a previously encrypted text.

use function Folded\getDecryptedString;

$encryptedString = "...";
$decryptedString = getDecryptedString($encryptedString);

Note it will only decrypt encrypted string from the getEncryptedString() function.

Also note that if you encrypt a string with a key A, and you change the key A for a new key, the getDecryptedString will not be able to successfuly decrypt the text and get the original text so be careful to save your key in somewhere safe (generally in a .env file).

Version support

7.3 7.4 8.0
v0.1.0 ✔️

crypt's People

Contributors

khalyomede avatar

Watchers

 avatar  avatar  avatar

crypt's Issues

Missing namespace in function_exists call

Description

When the code loads functions, it should detect the existance of the function under the namespace instead of just the name of the function

Expected behavior

The call of function_exists() use the full qualified namespace.

namespace Folded;

if (!function_exists("Folded\theFunction")) {
  // load the function now
}

Actual behavior

Functions declared twice enters in collision.

Alternatives solutions

None.

Add static analysis in the test command

Description

Static analysis helps catching bugs earlier.

Proposal

  • Using phpstan/phpstan and run the command after the test command: pest --coverage && phpstan analyse src
  • Use the level 8 for a maximum of consistency
  • Use a phpstan.neon configuration file

Worarkound solutions

None.

Notes

None.

The Crypt class is marked as final

Description

The Crypt class is not meant to be extended. Mark it as final.

Proposal

The class Crypt is marked as final.

Worarkound solutions

None.

Notes

None.

Add issues templates for both bugs and enhancements

Description

There is no templates for bugs and enhancements, which can reduce the chances someone will want to describe his issue or can make difficult to format and clarify an issue without proper templates.

Expected behavior

Enhancements issue template

For an enhancements, the following sections (using level 2 title, ##) should be shown:

  • Description
  • Proposal
  • Workaround solutions
  • Notes

The text hints, using italic, should be shown below each of these titles (without the double quotes):

  • Description: "Give some context and motivation for the proposed solution."
  • Proposal: "The detail proposition. Can include code."
  • Worarkound solutions: "Mention every existing workaround you know that will solve the issue apart from the proposed solution."
  • Notes: "Add everything that relates the proposal, like future induced issues, related issues, ..."

Bug issue template

For a bug, the following sections (using level 2 title, ##) should be shown:

  • Description
  • Steps to reproduce the issue
  • Expected behavior
  • Workaround solutions
  • Notes

The text hints, using italic, should be show below each of these titles (without the double quotes):

  • Description: "Any information that can give more understanding about how you came to this issue."
  • Steps to reproduce the issue: "Detail precisely how we can reproduce the issue from a blank new project (if possible)."
  • Expected behavior: "Describe what the output or the behavior should be instead of the issue you have."
  • Workaround solutions: "Mention every existing workaround you know that will solve the issue."
  • Notes: "Add everything that relates the proposal, like related issues, ..."

Alternatives solutions

To write by hand the issue layout.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.