mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-24 15:48:26 +00:00
RSA: update unit test
This commit is contained in:
parent
4329015629
commit
c489852332
@ -742,18 +742,18 @@ class Crypt_RSA
|
||||
*/
|
||||
function _convertPrivateKey($n, $e, $d, $primes, $exponents, $coefficients)
|
||||
{
|
||||
$unsigned = $this->privateKeyFormat == CRYPT_RSA_PRIVATE_FORMAT_XML;
|
||||
$signed = $this->privateKeyFormat != CRYPT_RSA_PRIVATE_FORMAT_XML;
|
||||
$num_primes = count($primes);
|
||||
$raw = array(
|
||||
'version' => $num_primes == 2 ? chr(0) : chr(1), // two-prime vs. multi
|
||||
'modulus' => $n->toBytes($unsigned),
|
||||
'publicExponent' => $e->toBytes($unsigned),
|
||||
'privateExponent' => $d->toBytes($unsigned),
|
||||
'prime1' => $primes[1]->toBytes($unsigned),
|
||||
'prime2' => $primes[2]->toBytes($unsigned),
|
||||
'exponent1' => $exponents[1]->toBytes($unsigned),
|
||||
'exponent2' => $exponents[2]->toBytes($unsigned),
|
||||
'coefficient' => $coefficients[2]->toBytes($unsigned)
|
||||
'modulus' => $n->toBytes($signed),
|
||||
'publicExponent' => $e->toBytes($signed),
|
||||
'privateExponent' => $d->toBytes($signed),
|
||||
'prime1' => $primes[1]->toBytes($signed),
|
||||
'prime2' => $primes[2]->toBytes($signed),
|
||||
'exponent1' => $exponents[1]->toBytes($signed),
|
||||
'exponent2' => $exponents[2]->toBytes($signed),
|
||||
'coefficient' => $coefficients[2]->toBytes($signed)
|
||||
);
|
||||
|
||||
// if the format in question does not support multi-prime rsa and multi-prime rsa was used,
|
||||
@ -942,10 +942,10 @@ class Crypt_RSA
|
||||
*/
|
||||
function _convertPublicKey($n, $e)
|
||||
{
|
||||
$unsigned = $this->publicKeyFormat == CRYPT_RSA_PUBLIC_FORMAT_XML;
|
||||
$signed = $this->publicKeyFormat != CRYPT_RSA_PUBLIC_FORMAT_XML;
|
||||
|
||||
$modulus = $n->toBytes($unsigned);
|
||||
$publicExponent = $e->toBytes($unsigned);
|
||||
$modulus = $n->toBytes($signed);
|
||||
$publicExponent = $e->toBytes($signed);
|
||||
|
||||
switch ($this->publicKeyFormat) {
|
||||
case CRYPT_RSA_PUBLIC_FORMAT_RAW:
|
||||
|
@ -270,13 +270,35 @@ Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
|
||||
$rsa = new Crypt_RSA();
|
||||
|
||||
$key = '<RSAKeyValue>
|
||||
<Modulus>v5OxcEgxPUfa701NpxnScCmlRkbwSGBiTWobHkIWZEB+AlRTHaVoZg/D8l6YzR7VdQidG6gF+nuUMjY75dBXgY/XcyVq0Hccf1jTfgARuNuq4GGG3hnCJVi2QsOgcf9R7TeXn+p1RKIhjQoWCiEQeEBTotNbJhcabNcPGSEJw+s=</Modulus>
|
||||
<Exponent>AQAB</Exponent>
|
||||
<Modulus>v5OxcEgxPUfa701NpxnScCmlRkbwSGBiTWobHkIWZEB+AlRTHaVoZg/D8l6YzR7VdQidG6gF+nuUMjY75dBXgY/XcyVq0Hccf1jTfgARuNuq4GGG3hnCJVi2QsOgcf9R7TeXn+p1RKIhjQoWCiEQeEBTotNbJhcabNcPGSEJw+s=</Modulus>
|
||||
<Exponent>AQAB</Exponent>
|
||||
</RSAKeyValue>';
|
||||
|
||||
$rsa->loadKey($key);
|
||||
$rsa->setPublicKey();
|
||||
$newkey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_XML);
|
||||
|
||||
$this->assertSame($key, $newkey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group github468
|
||||
*/
|
||||
public function testSignedPKCS1()
|
||||
{
|
||||
$rsa = new Crypt_RSA();
|
||||
|
||||
$key = '-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/k7FwSDE9R9rvTU2nGdJwKaVG
|
||||
RvBIYGJNahseQhZkQH4CVFMdpWhmD8PyXpjNHtV1CJ0bqAX6e5QyNjvl0FeBj9dz
|
||||
JWrQdxx/WNN+ABG426rgYYbeGcIlWLZCw6Bx/1HtN5ef6nVEoiGNChYKIRB4QFOi
|
||||
01smFxps1w8ZIQnD6wIDAQAB
|
||||
-----END PUBLIC KEY-----';
|
||||
|
||||
$rsa->loadKey($key);
|
||||
$rsa->setPublicKey();
|
||||
$newkey = $rsa->getPublicKey();
|
||||
|
||||
$this->assertSame($key, $newkey);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user