Skip to content

Commit da43a00

Browse files
committed
added first working version
0 parents commit da43a00

25 files changed

+5405
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[*.*]
2+
3+
indent_size = 4
4+
indent_style = space
5+
insert_final_newline = true
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
9+
[*.md]
10+
11+
indent_size = 2
12+
13+
[*.yml]
14+
15+
indent_size = 2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
.phpunit.result.cache

.php_cs

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
8+
$finder = Finder::create()->in(__DIR__);
9+
10+
return Config::create()
11+
->setUsingCache(false)
12+
->setFinder($finder)
13+
->setRules([
14+
"@PSR2" => true,
15+
"align_multiline_comment" => [
16+
"comment_type" => "phpdocs_like",
17+
],
18+
"array_indentation" => true,
19+
"array_syntax" => [
20+
"syntax" => "short",
21+
],
22+
"blank_line_after_opening_tag" => true,
23+
"blank_line_before_statement" => true,
24+
"cast_spaces" => [
25+
"space" => "single",
26+
],
27+
"class_attributes_separation" => [
28+
"elements" => ["const", "method", "property"],
29+
],
30+
"combine_consecutive_issets" => true,
31+
"combine_consecutive_unsets" => true,
32+
"compact_nullable_typehint" => true,
33+
"concat_space" => [
34+
"spacing" => "one",
35+
],
36+
"declare_equal_normalize" => [
37+
"space" => "single",
38+
],
39+
"declare_strict_types" => true,
40+
"dir_constant" => true,
41+
"ereg_to_preg" => true,
42+
"explicit_indirect_variable" => true,
43+
"fopen_flag_order" => true,
44+
"function_to_constant" => [
45+
"functions" => ["get_class", "php_sapi_name", "phpversion", "pi"],
46+
],
47+
"function_typehint_space" => true,
48+
"global_namespace_import" => [
49+
"import_classes" => true,
50+
"import_constants" => true,
51+
"import_functions" => true,
52+
],
53+
"implode_call" => true,
54+
"include" => true,
55+
"increment_style" => [
56+
"style" => "post",
57+
],
58+
"is_null" => [
59+
"use_yoda_style" => false,
60+
],
61+
"linebreak_after_opening_tag" => true,
62+
"list_syntax" => [
63+
"syntax" => "short",
64+
],
65+
"logical_operators" => true,
66+
"lowercase_cast" => true,
67+
"lowercase_static_reference" => true,
68+
"magic_constant_casing" => true,
69+
"magic_method_casing" => true,
70+
"mb_str_functions" => true,
71+
"method_chaining_indentation" => true,
72+
"modernize_types_casting" => true,
73+
"modernize_types_casting" => true,
74+
"multiline_whitespace_before_semicolons" => [
75+
"strategy" => "no_multi_line",
76+
],
77+
"native_function_casing" => true,
78+
"native_function_type_declaration_casing" => true,
79+
"new_with_braces" => true,
80+
"no_alternative_syntax" => true,
81+
"no_binary_string" => true,
82+
"no_blank_lines_after_class_opening" => true,
83+
"no_blank_lines_after_phpdoc" => true,
84+
"no_empty_comment" => true,
85+
"no_empty_phpdoc" => true,
86+
"no_empty_statement" => true,
87+
"no_extra_blank_lines" => [
88+
"tokens" => ["break", "case", "continue", "curly_brace_block", "default", "extra", "parenthesis_brace_block", "return", "square_brace_block", "switch", "throw", "use", "useTrait", "use_trait"],
89+
],
90+
"no_homoglyph_names" => true,
91+
"no_leading_import_slash" => true,
92+
"no_leading_namespace_whitespace" => true,
93+
"no_mixed_echo_print" => [
94+
"use" => "echo",
95+
],
96+
"no_multiline_whitespace_around_double_arrow" => true,
97+
"no_null_property_initialization" => true,
98+
"no_php4_constructor" => true,
99+
"no_short_bool_cast" => true,
100+
"no_short_echo_tag" => true,
101+
"no_singleline_whitespace_before_semicolons" => true,
102+
"no_spaces_around_offset" => true,
103+
"no_superfluous_elseif" => true,
104+
"no_superfluous_phpdoc_tags" => [
105+
"allow_mixed" => false,
106+
"allow_unused_params" => false,
107+
"remove_inheritdoc" => false,
108+
],
109+
"no_trailing_comma_in_list_call" => true,
110+
"no_trailing_comma_in_singleline_array" => true,
111+
"no_unneeded_control_parentheses" => [
112+
"statements" => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
113+
],
114+
"no_unneeded_curly_braces" => [
115+
"namespaces" => true,
116+
],
117+
"no_unneeded_final_method" => true,
118+
"no_unreachable_default_argument_value" => true,
119+
"no_unset_cast" => true,
120+
"no_unset_on_property" => true,
121+
"no_unused_imports" => true,
122+
"no_useless_else" => true,
123+
"no_useless_return" => true,
124+
"no_whitespace_before_comma_in_array" => [
125+
"after_heredoc" => false,
126+
],
127+
"no_whitespace_in_blank_line" => true,
128+
"non_printable_character" => [
129+
"use_escape_sequences_in_strings" => false,
130+
],
131+
"normalize_index_brace" => true,
132+
"object_operator_without_whitespace" => true,
133+
"ordered_class_elements" => [
134+
"order" => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private'],
135+
"sortAlgorithm" => "alpha",
136+
],
137+
"ordered_interfaces" => [
138+
"direction" => "ascend",
139+
"order" => "alpha",
140+
],
141+
"phpdoc_add_missing_param_annotation" => [
142+
"only_untyped" => true,
143+
],
144+
"phpdoc_align" => [
145+
"align" => "vertical",
146+
"tags" => ['param', 'return', 'throws', 'type', 'var'],
147+
],
148+
"phpdoc_indent" => true,
149+
"phpdoc_no_empty_return" => true,
150+
"phpdoc_order" => true,
151+
"phpdoc_scalar" => [
152+
"types" => ['boolean', 'double', 'integer', 'real', 'str'],
153+
],
154+
"phpdoc_separation" => true,
155+
"phpdoc_single_line_var_spacing" => true,
156+
"phpdoc_to_comment" => true,
157+
"phpdoc_trim" => true,
158+
"phpdoc_trim_consecutive_blank_line_separation" => true,
159+
"phpdoc_types" => [
160+
"groups" => ['simple', 'alias', 'meta'],
161+
],
162+
"phpdoc_types_order" => [
163+
"null_adjustment" => "always_first",
164+
"sort_algorithm" => "alpha",
165+
],
166+
"phpdoc_var_annotation_correct_order" => true,
167+
"phpdoc_var_without_name" => true,
168+
"pow_to_exponentiation" => true,
169+
"protected_to_private" => true,
170+
"psr4" => true,
171+
"random_api_migration" => [
172+
"replacements" => ['getrandmax' => 'mt_getrandmax', 'rand' => 'mt_rand', 'srand' => 'mt_srand'],
173+
],
174+
"return_assignment" => true,
175+
"return_type_declaration" => [
176+
"space_before" => "none",
177+
],
178+
"self_accessor" => true,
179+
"self_static_accessor" => true,
180+
"semicolon_after_instruction" => true,
181+
"set_type_to_cast" => true,
182+
"short_scalar_cast" => true,
183+
"simple_to_complex_string_variable" => true,
184+
"simplified_null_return" => true,
185+
"single_blank_line_before_namespace" => true,
186+
"single_class_element_per_statement" => [
187+
"elements" => ['const', 'property'],
188+
],
189+
"single_line_comment_style" => [
190+
"comment_types" => ['asterisk', 'hash'],
191+
],
192+
"single_line_throw" => true,
193+
"single_trait_insert_per_statement" => true,
194+
"space_after_semicolon" => [
195+
"remove_in_empty_for_expressions" => false,
196+
],
197+
"standardize_increment" => true,
198+
"standardize_not_equals" => true,
199+
"strict_param" => true,
200+
"switch_case_semicolon_to_colon" => true,
201+
"switch_case_space" => true,
202+
"ternary_operator_spaces" => true,
203+
"ternary_to_null_coalescing" => true,
204+
"trailing_comma_in_multiline_array" => [
205+
"after_heredoc" => false,
206+
],
207+
"trim_array_spaces" => true,
208+
"unary_operator_spaces" => true,
209+
"visibility_required" => [
210+
"elements" => ['property', 'method'],
211+
],
212+
"void_return" => true,
213+
"whitespace_after_comma_in_array" => true,
214+
]);

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: php
2+
php:
3+
- 7.4.5
4+
before_script: composer install
5+
script: composer run test

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.0] 2020-09-17
11+
12+
### Added
13+
14+
- First working version.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Folded
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# folded/crypt
2+
3+
Easily encrypt and decrypt strings for your web app.
4+
5+
## Summary
6+
7+
- [About](#about)
8+
- [Features](#features)
9+
- [Requirements](#requirements)
10+
- [Installation](#installation)
11+
- [Examples](#examples)
12+
- [Version support](#version-support)
13+
14+
## About
15+
16+
I created this library to be able to encrypt my data in a standalone way.
17+
18+
Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.
19+
20+
- [folded/action](https://github.com/folded-php/action): A way to organize your controllers for your web app.
21+
- [folded/config](https://github.com/folded-php/config): Configuration utilities for your PHP web app.
22+
- [folded/exception](https://github.com/folded-php/exception): Various kind of exception to throw for your web app.
23+
- [folded/history](https://github.com/folded-php/history): Manipulate the browser history for your web app.
24+
- [folded/http](https://github.com/folded-php/http): HTTP utilities for your web app.
25+
- [folded/orm](https://github.com/folded-php/orm): An ORM for you web app.
26+
- [folded/request](https://github.com/folded-php/request): Request utilities, including a request validator, for your PHP web app.
27+
- [folded/routing](https://github.com/folded-php/routing): Routing functions for your PHP web app.
28+
- [folded/session](https://github.com/folded-php/session): Session functions for your web app.
29+
- [folded/view](https://github.com/folded-php/view): View utilities for your PHP web app.
30+
31+
## Features
32+
33+
- Can encrypt and decrypt strings
34+
- Can generate a key (necessary to setup the library) from the command line
35+
36+
## Requirements
37+
38+
- PHP >= 7.4.0
39+
- Composer installed
40+
41+
## Installation
42+
43+
- [1. Install the package](#1-install-the-package)
44+
- [2. Generate a key](#2-generate-a-key)
45+
- [3. Add the setup code](#3-add-the-setup-code)
46+
47+
### 1. Install the package
48+
49+
In your root folder, run this command:
50+
51+
```bash
52+
composer require folded/crypt
53+
```
54+
55+
### 2. Generate a key
56+
57+
One way to generate the key easily is through the command line. Run this command to get a new key:
58+
59+
```bash
60+
vendor/bin/crypt generate key
61+
```
62+
63+
You can get more information on the available option by running `vendor/bin/crypt generate --help`.
64+
65+
Another way is to call the function `Folded\generateEncryptionKey()` from a script:
66+
67+
```php
68+
use Folded\generateEncryptionKey;
69+
70+
require __DIR__ . "/vendor/autoload.php";
71+
72+
echo generateEncryptionKey();
73+
```
74+
75+
You can add a parameter to control the type of cipher you want (currently supported: AES-128-CBC and AES-256-CBC).
76+
77+
### 3. Add the setup code
78+
79+
Before calling the library, add this setup code as early as possible:
80+
81+
```php
82+
use Folded\setEncryptionKey;
83+
84+
setEncryptionKey("xIYrZSsCV6hx9x/Q4bka1PejU+aSaMerJQFSYr3QnTE=");
85+
```
86+
87+
## Examples
88+
89+
- [1. Encrypt a string](#1-encrypt-a-string)
90+
- [2. Decrypt a string](#2-decrypt-a-string)
91+
92+
### 1. Encrypt a string
93+
94+
In this example, we will get the encrypted version of a string.
95+
96+
```php
97+
use function Folded\getEncryptedString;
98+
99+
$encryptedText = getEncryptedString("hello world");
100+
```
101+
102+
### 2. Decrypt a string
103+
104+
In this example, we will decrypt a previously encrypted text.
105+
106+
```php
107+
use function Folded\getDecryptedString;
108+
109+
$encryptedString = "...";
110+
$decryptedString = getDecryptedString($encryptedString);
111+
```
112+
113+
Note it will only decrypt encrypted string from the `getEncryptedString()` function.
114+
115+
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).
116+
117+
## Version support
118+
119+
| | 7.3 | 7.4 | 8.0 |
120+
| ------ | --- | --- | --- |
121+
| v0.1.0 || ✔️ ||

0 commit comments

Comments
 (0)