shizzo91/crypto 问题修复 & 功能扩展

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

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

shizzo91/crypto

Composer 安装命令:

composer require shizzo91/crypto

包简介

From symmetric to hybrid encryption, everything is possible. There is symmetric encryption, asymmetric encryption, multiple asymmetric encryption, hybrid encryption and multiple hybrid encryption.

README 文档

README

Symmetrical

usage

    // encoding
    $password = "password";
    $symmetricalCrypto = new SymmetricalCrypto($password);
    $encoded = $symmetricalCrypto->encode("Stringable or string"); 

    // decoding
    $password = "password";
    $symmetricalCrypto = new SymmetricalCrypto($password);
    $decode = $symmetricalCrypto->decode($encoded); 

Asymmetric or Hybrid

create a RSA key

# Private key generation (with passphrase)
openssl req -new -nodes -sha512 -newkey rsa:2048 -keyout private.pem 
# Private key generation (without passphrase)
openssl req -nodes -new -x509 -keyout private.pem 
# Public key extraction
openssl rsa -in private.pem -pubout -out public.pem

usage for simple asymmetric

    $privateSimpleCrypto = new PrivateSimpleCrypto(
        "../private-2.pem", // file or text
        "passphrase" // passphrase optional
    );
    $encoded = $privateSimpleCrypto->encode("Stringable or string"); 

    $publicSimpleCrypto = new PublicSimpleCrypto(
        "../public-2.pem" // file or text
    );
    $decode = $publicSimpleCrypto->decode($encoded); 

usage for double asymmetric

    // simple
    // encoding
    $privateSimpleCrypto = new PrivateSimpleCrypto(
        "../private-2.pem", // file or text
        "passphrase" // passphrase optional
    );
    $encoded = $privateSimpleCrypto->encode("Stringable or string"); 
    
    // decoding
    $publicSimpleCrypto = new PublicSimpleCrypto(
        "../public-2.pem" // file or text
    );
    $decode = $publicSimpleCrypto->decode($encoded); 
    
    // double
    // encoding
    $myPrivateKey = new PrivateSimpleCrypto("../private.pem");
    $receiverPublicKey = new PublicSimpleCrypto("../public-2.pem");
    $doubleCrypto = new DoubleCrypto(
        $receiverPublicKey,
        $myPrivateKey
    );
    $encoded = $doubleCrypto->encode("Stringable or string"); 

    
    // decoding
    // with text as key
    $receiverPrivateKey = "-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----";
    $myPublicKey = "../public.pem";

    $doubleCryptoReceiver = DoubleCrypto::create($myPublicKey, $receiverPrivateKey, "secret");
    $decoded = $doubleCryptoReceiver->decode($encoded);
    var_dump($decoded); // "Stringable or string"

usage for hybrid

    // simple
    // encoding
    $simpleHybridPrivate = HybridCrypto::createPrivateSimple("password", "../private.pem");
    $encoded = $simpleHybridPrivate->encode("Stringable or string");

    // decoding
    $simpleHybridPublic = HybridCrypto::createPublicSimple("password", "../public.pem");
    $decoded = $simpleHybridPublic->encode($encoded);

    // double
    // encoding
    $doubleHybridTransmitter = HybridCrypto::createDouble(
        "password",
        "../public-2.pem",
        "../private.pem"
    );
    $encoded = $doubleHybridTransmitter->encode("Stringable or string");

    // decoding
    $doubleHybridReceiver = HybridCrypto::createDouble(
        "password",
        "../public.pem",
        "../private-2.pem",
        "passphrase"
    );
    $decoded = $doubleHybridReceiver->encode($encoded);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-03