juanchosl/cryptology
Composer 安装命令:
composer require juanchosl/cryptology
包简介
Little encrypt/decrypt tools in order to crypt, decrypt, sign or verify messages, tests or files using distincts formats with the same way
README 文档
README
This library brings together different reversible encryption systems, keeping the parameterization unified with the idea of being able to change systems without maintenance in the code, simply adapting the constructions of the instances
Instalation
use composer in order to install it
composer require juanchosl\cryptology
Types
Open SSL
Symmetric Password
The same password in plain text format for encode and decode, all receivers need to know the password
Options
- cipher: a cipher algorithm available, can check the response from openssl_get_cipher_methods()
Examples
$crypter = new Password; $crypter->setPassword('myPassword'); $crypted_message = $crypter->encrypt('A message to encrypt'); $decrypter = new Password; $decrypter->setPassword('myPassword'); $decrypted_message = $decrypter->decrypt($crypted_message);
Asymmetric PrivateKey/PublicKey
One to one, if the sender encode using the privatekey, the receiver needs to decode using the related public key
Options
- padding: OPENSSL_PKCS1_PADDING or OPENSSL_NO_PADDING
Examples
$crypter = new PrivateKey; $crypter->setPrivateKey('/path/to/private_key.key'); $crypted_message = $crypter->encrypt('A message to encrypt'); $decrypter = new PublicKey; $decrypter->setPublicKey('/path/to/public_key.pub'); $decrypted_message = $decrypter->decrypt($crypted_message);
Pkcs1
For all message types, send to some using public keys but generating an exclusive passphrase for each receiver, any one need to decode using his private key and the passphrase of the message
Options
- cipher: a cipher algorithm available, can check the response from openssl_get_cipher_methods()
- algo: an algorithm method available, can check the response from openssl_get_md_methods()
Examples
$crypter = new Pkcs1; $crypter->setRemotes(['/path/to/receiver/certificate.crt']); $crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response $decrypter = new Pkcs1; $decrypter->setPrivateKey('/path/to/my/private_key.key'); $decrypter->setPublicKey('/path/to/public_key.pub'); $decrypter->setPassword('message_password'); $decrypted_message = $decrypter->decrypt($crypted_message);
You can sign the sended message with your own private key in order to ensure your identity
$crypter = new Pkcs1; $crypter->setRemotes(['/path/to/receiver/certificate.crt']); $crypter->setPrivateKey('/path/to/my/private_key.key'); $signed_message = $crypter->sign('A message to sign');
And verify the received message using the sender certificate
$decrypter = new Pkcs1; $decrypter->setRemotes(['/path/to/sender/certificate.crt']); $message = $decrypter->verify($signed_message);
Pkcs7
For SMIME messages, send to some using receivers certificates and decode using the private key. We can sign the messages in order to apply a certification of sender
Options
- cipher: a cipher constant from openssl, by default OPENSSL_CIPHER_AES_256_CBC
Examples
$crypter = new Pkcs7; $crypter->setRemotes(['/path/to/receiver/certificate.crt']); $crypted_message = $crypter->encrypt('A message to encrypt'); $decrypter = new Pkcs7; $decrypter->setPrivateKey('/path/to/my/private_key.key'); $decrypter->setCertificate('/path/to/my/certificate.crt'); $decrypter->setRemotes(['/path/to/sender/certificate.crt']); $decrypted_message = $decrypter->decrypt($crypted_message);
You can sign the sended message with your own private key in order to ensure your identity
$crypter = new Pkcs7; $crypter->setPrivateKey('/path/to/my/private_key.key'); $crypter->setCertificate('/path/to/my/certificate.crt'); $signed_message = $crypter->sign('A message to encrypt');
And verify the received message using the sender certificate
$decrypter = new Pkcs7; $decrypter->setRemotes(['/path/to/sender/certificate.crt']); $message = $decrypter->verify($signed_message);
CMS
For multipurpose messages, send to some using receivers certificates and decode using our own private key and certificate. We can sign the messages in order to apply a certification of sender
Options
- encoding: OPENSSL_ENCODING_PEM, OPENSSL_ENCODING_SMIME or OPENSSL_ENCODING_DER (by default)
- cipher: a cipher constant from openssl, by default OPENSSL_CIPHER_AES_256_CBC
Examples
$crypter = new Cms; $crypter->setRemotes(['/path/to/receiver/certificate.crt']); $crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response $decrypter = new Cms; $decrypter->setPrivateKey('/path/to/my/private_key.key'); $decrypter->setCertificate('/path/to/my/certificate.crt'); $decrypted_message = $decrypter->decrypt($crypted_message);
You can sign the sended message with your own private key in order to ensure your identity
$crypter = new Cms; $crypter->setRemotes(['/path/to/receiver/certificate.crt']); $crypter->setPrivateKey('/path/to/my/private_key.key'); $decrypter->setCertificate('/path/to/my/certificate.crt'); $signed_message = $crypter->sign('A message to sign');
And verify the received message using the sender certificate
$decrypter = new Cms; $decrypter->setRemotes(['/path/to/sender/certificate.crt']); $message = $decrypter->verify($signed_message);
Gpg
For use the Open GPG standard
Gnupg
Require the gnupg library installed for php
Examples
$crypter = new Gnupg; $crypter->setRemotes(['/path/to/receiver/certificate.crt']); $crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response $decrypter = new Gnupg; $decrypter->setPrivateKey('/path/to/my/private_key.key'); $decrypted_message = $decrypter->decrypt($crypted_message);
You can sign the sended message with your own private key in order to ensure your identity
$crypter = new Gnupg; $crypter->setRemotes(['/path/to/receiver/certificate.crt']); $crypter->setPrivateKey('/path/to/my/private_key.key'); $signed_message = $crypter->sign('A message to sign');
And verify the received message using the sender certificate
$decrypter = new Gnupg; $decrypter->setPrivateKey('/path/to/my/private_key.key'); $decrypter->setRemotes(['/path/to/sender/certificate.crt']); $message = $decrypter->verify($signed_message);
GpgConsole
Require the gpg library installed for console
Examples
$crypter = new GpgConsole; $crypter->setRemotes(['receiver_fingerprint']); $crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response $decrypter = new GpgConsole; $decrypter->setPrivateKey('private_fingerprint'); $decrypted_message = $decrypter->decrypt($crypted_message);
You can sign the sended message with your own private key in order to ensure your identity
$crypter = new GpgConsole; $crypter->setPrivateKey('private_fingerprint'); $crypter->setRemotes(['receiver_fingerprint']); $signed_message = $crypter->sign('A message to sign');
And verify the received message using the sender certificate
$decrypter = new GpgConsole; $decrypter->setPrivateKey('private_fingerprint'); $decrypter->setRemotes(['sender_fingerprint']); $message = $decrypter->verify($signed_message);
Older systems
We add an older type of encryption in order to be able to mantain our systems
Mcrypt
The same password in plain text format for encode and decode, all receivers need to know the password
$crypter = new Mcrypt; $crypter->setPassword('myPassword'); $crypted_message = $crypter->encrypt('A message to encrypt'); $decrypter = new Mcrypt; $decrypter->setPassword('myPassword'); $decrypted_message = $decrypter->decrypt($crypted_message);
Utils
For create a GPG key use the console and follow the instructions, updating the phpunit.xml with the new credentials
root@1be56db22035:/application# gpg --full-generate-key gpg (GnuPG) 2.2.40; Copyright (C) 2022 g10 Code GmbH This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) (14) Existing key from card Your selection? 1 RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (3072) 1024 Requested keysize is 1024 bits Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 365 Key expires at Wed Oct 15 17:10:13 2025 UTC Is this correct? (y/N) y GnuPG needs to construct a user ID to identify your key. Real name: Juan Sanchez Email address: JuanchoSL@hotmail.com Comment: Cryptology You selected this USER-ID: "Juan Sanchez (Cryptology) <JuanchoSL@hotmail.com>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. gpg: directory '/root/.gnupg/openpgp-revocs.d' created gpg: revocation certificate stored as '/root/.gnupg/openpgp-revocs.d/572A0A03F67FD96351BBF7F3FC869096CAF45839.rev' public and secret key created and signed. pub rsa1024 2024-10-15 [SC] [expires: 2025-10-15] 572A0A03F67FD96351BBF7F3FC869096CAF45839 uid Juan Sanchez (Cryptology) <JuanchoSL@hotmail.com> sub rsa1024 2024-10-15 [E] [expires: 2025-10-15]
juanchosl/cryptology 适用场景与选型建议
juanchosl/cryptology 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「crypt」 「openssl」 「encrypt」 「mcrypt」 「decrypt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 juanchosl/cryptology 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juanchosl/cryptology 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 juanchosl/cryptology 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Composer friendly version of http://web.archive.org/web/20130727034425/http://blog.kevburnsjr.com/php-unique-hash
A PHP library to encrypt/decrypt secrets using OpenSSL.
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Strong cryptography tools and password hashing
统计信息
- 总下载量: 66
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-15