strukt / key
密码学
v1.1.0-alpha
2024-03-24 23:50 UTC
Requires
- php: ^8.1
- ext-openssl: *
- firebase/php-jwt: ^6.10
- strukt/commons: v1.1.1-alpha
- strukt/console: 1.0.0
- symfony/http-foundation: ^4.2
This package is auto-updated.
Last update: 2024-09-06 20:06:04 UTC
README
安装
Composer
创建以下内容的composer.json
脚本,然后运行composer update
{ "require":{ "strukt/key":"v1.1.0-alpha" }, "minimum-stability":"dev" }
哈希
Bcrypt
$hash = bcry("p@55w0rd")->encode() $success = bcry("p@55w0rd")->verify($hash);
Sha256 (加倍)
$hash = sha256dbl('p@55w0rd');
公钥和私钥
自动生成密钥
$k = Strukt\Ssl\All::makeKeys() $k->getKeys()->getPrivateKey()->getPem()//get private key $k->getKeys()->getPublicKey()->getPem()//get public key $c = $k->useCipher() $enc = $c->encrypt("p@55w0rd") $dec = $c->decrypt($enc)
使用现有密钥
如果你想要的话,可以通过ssh-keygen
生成你的密钥。
$file = "file:///home/churchill/.ssh/id_rsa" $k = Strukt\Ssl\All::keyPath($file)
使用公钥加密消息
$message = "Hi! My name is (what?) My name is (who?) My name is Slim Shady Hi! My name is (huh?) My name is (what?) My name is Slim Shady"; $file = "file:///home/churchill/.ssh/id_rsa.pub" $p = new Strukt\Ssl\KeyPair();//No private key $p->setPublicKey($file); $enc = Strukt\Ssl\All::useKeys($p)->toSend($message);
使用密码加密
$p = new Strukt\Ssl\KeyPair($path, "p@55w0rd"); $p->getPublicKey()//trigger public key extraction from private key $k = Strukt\Ssl\All::useKeys($p)
证书签名请求 (CSR)
签名并验证证书
$kpath = "file:///home/churchill/.ssh/id_rsa" $cpath = "file:///home/churchill/.ssh/cacert.pem" $oCsr = Strukt\Ssl\All::keyPath($kpath)->withCert($cpath); $cert = $oCsr->sign(); $success = $oCsr->verify($cert);