togos / rsa-util
用于生成和验证RSA签名的库
0.1.0
2015-11-13 18:55 UTC
Requires
- php: >=5.2
Requires (Dev)
- earthit/php-common: ^1.1.0
- phpunit/phpunit: ^3.7
- togos/base32: ^1.0.1
- togos/png-chunks: ^1.0.1
This package is auto-updated.
Last update: 2024-09-20 03:55:53 UTC
README
PHP RSA Util
用于生成和验证签名以及在不同密钥格式之间转换的工具。
主要操作围绕TOGoS_RSAUtil_Signature
对象,它代表使用特定密钥对特定数据进行签名。签名表示密钥和数据(可以是内联或通过哈希URI),用于计算签名的算法以及签名数据本身。
请参阅http://www.nuke24.net/docs/2012/RSA.html,以获取关于密钥格式的个人信息收集。
使用示例
/* * Assuming $dataStore is an object that the guy verifying also has * access to */ $privateKey = file_get_contents('private-key.der'); // Will work with 'pem' files, too. $publicKey = file_get_contents('public-key.der'); $payload = "Hello!"; $dataStore->store($payload); $dataStore->store($publicKey); $publicKeyUri = "urn:sha1:".TOGoS_Base32::encode(hash('sha1',$publicKey,true)); $sig = TOGoS_RSAUtil::sign($payload, $privateKey, OPENSSL_ALGO_SHA1); $sigCodec = new TOGoS_RSAUtil_XKRTSignatureCodec(); $sigBlob = $sigCodec->encode($sig);
发送$sigBlob
给某人,他们可以...
/* * Assuming $dataStore and $sigBlob are input variables * Using XKRT codec, the public key and payload data are referenced by * but not contained in the signature. We fetch them from $dataStore. */ $sigCodec = new TOGoS_RSAUtil_XKRTSignatureCodec(); $sig = $sigCodec->decode($sigBlob); TOGoS_RSAUtil::verify($sig, $dataStore); echo "Signature was valid! Here's the data!\n"; echo (string)$dataStore->getBlob($sig->getPayloadUri());