2013-12-27 16:41:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-02-15 18:57:49 +00:00
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
2014-12-09 23:02:44 +00:00
|
|
|
* @copyright 2013 Jim Wigginton
|
2014-02-15 18:57:49 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2013-12-27 16:41:07 +00:00
|
|
|
*/
|
|
|
|
|
2014-12-17 00:16:54 +00:00
|
|
|
use phpseclib\Crypt\RSA;
|
2014-02-15 18:57:49 +00:00
|
|
|
|
2014-06-01 19:13:20 +00:00
|
|
|
class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
|
2013-12-27 16:41:07 +00:00
|
|
|
{
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testBadKey()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$key = 'zzzzzzzzzzzzzz';
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertFalse($rsa->load($key));
|
2014-02-15 18:57:49 +00:00
|
|
|
}
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testPKCS1Key()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$key = '-----BEGIN RSA PRIVATE KEY-----
|
2013-12-27 16:41:07 +00:00
|
|
|
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
|
|
|
|
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
|
|
|
|
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
|
|
|
|
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
|
|
|
|
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
|
|
|
|
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
|
|
|
|
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
|
|
|
|
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
|
|
|
|
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
|
|
|
|
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
|
|
|
|
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
|
|
|
|
-----END RSA PRIVATE KEY-----';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPrivateKey());
|
2014-02-15 18:57:49 +00:00
|
|
|
}
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testPKCS1SpacesKey()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$key = '-----BEGIN RSA PRIVATE KEY-----
|
2013-12-27 16:41:07 +00:00
|
|
|
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
|
|
|
|
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
|
|
|
|
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
|
|
|
|
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
|
|
|
|
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
|
|
|
|
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
|
|
|
|
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
|
|
|
|
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
|
|
|
|
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
|
|
|
|
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
|
|
|
|
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
|
|
|
|
-----END RSA PRIVATE KEY-----';
|
2014-02-15 18:57:49 +00:00
|
|
|
$key = str_replace(array("\r", "\n", "\r\n"), ' ', $key);
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPrivateKey());
|
2014-02-15 18:57:49 +00:00
|
|
|
}
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testPKCS1NoHeaderKey()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$key = 'MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
|
2013-12-27 16:41:07 +00:00
|
|
|
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
|
|
|
|
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
|
|
|
|
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
|
|
|
|
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
|
|
|
|
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
|
|
|
|
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
|
|
|
|
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
|
|
|
|
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
|
|
|
|
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
|
|
|
|
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPrivateKey());
|
2014-02-15 18:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPKCS1NoWhitespaceNoHeaderKey()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-02-15 18:57:49 +00:00
|
|
|
|
|
|
|
$key = 'MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp' .
|
|
|
|
'wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5' .
|
|
|
|
'1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh' .
|
|
|
|
'3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2' .
|
|
|
|
'pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX' .
|
|
|
|
'GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il' .
|
|
|
|
'AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF' .
|
|
|
|
'L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k' .
|
|
|
|
'X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl' .
|
|
|
|
'U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ' .
|
|
|
|
'37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=';
|
2014-04-18 16:41:08 +00:00
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPrivateKey());
|
2014-02-15 18:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRawPKCS1Key()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-02-15 18:57:49 +00:00
|
|
|
|
|
|
|
$key = 'MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp' .
|
|
|
|
'wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5' .
|
|
|
|
'1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh' .
|
|
|
|
'3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2' .
|
|
|
|
'pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX' .
|
|
|
|
'GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il' .
|
|
|
|
'AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF' .
|
|
|
|
'L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k' .
|
|
|
|
'X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl' .
|
|
|
|
'U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ' .
|
|
|
|
'37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=';
|
|
|
|
$key = base64_decode($key);
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPrivateKey());
|
2014-04-17 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 17:39:12 +00:00
|
|
|
public function testLoadPKCS8PrivateKey()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-06-13 17:39:12 +00:00
|
|
|
$rsa->setPassword('password');
|
|
|
|
|
|
|
|
$key = '-----BEGIN ENCRYPTED PRIVATE KEY-----
|
|
|
|
MIIE6TAbBgkqhkiG9w0BBQMwDgQIcWWgZeQYPTcCAggABIIEyLoa5b3ktcPmy4VB
|
|
|
|
hHkpHzVSEsKJPmQTUaQvUwIp6+hYZeuOk78EPehrYJ/QezwJRdyBoD51oOxqWCE2
|
|
|
|
fZ5Wf6Mi/9NIuPyqQccP2ouErcMAcDLaAx9C0Ot37yoG0S6hOZgaxqwnCdGYKHgS
|
|
|
|
7cYUv40kLOJmTOJlHJbatfXHocrHcHkCBJ1q8wApA1KVQIZsqmyBUBuwbrfFwpC9
|
|
|
|
d/R674XxCWJpXvU63VNZRFYUvd7YEWCrdSeleb99p0Vn1kxI5463PXurgs/7GPiO
|
|
|
|
SLSdX44DESP9l7lXenC4gbuT8P0xQRDzGrB5l9HHoV3KMXFODWTMnLcp1nuhA0OT
|
|
|
|
fPS2yzT9zJgqHiVKWgcUUJ5uDelVfnsmDhnh428p0GBFbniH07qREC9kq78UqQNI
|
|
|
|
Kybp4jQ4sPs64zdYm/VyLWtAYz8QNAKHLcnPwmTPr/XlJmox8rlQhuSQTK8E+lDr
|
|
|
|
TOKpydrijN3lF+pgyUuUj6Ha8TLMcOOwqcrpBig4SGYoB56gjAO0yTE9uCPdBakj
|
|
|
|
yxi3ksn51ErigGM2pGMNcVdwkpJ/x+DEBBO0auy3t9xqM6LK8pwNcOT1EWO+16zY
|
|
|
|
79LVSavc49t+XxMc3Xasz/G5xQgD1FBp6pEnsg5JhTTG/ih6Y/DQD8z3prjC3qKc
|
|
|
|
rpL4NA9KBI/IF1iIXlrfmN/zCKbBuEOEGqwcHBDHPySZbhL2XLSpGcK/NBl1bo1Z
|
|
|
|
G+2nUTauoC67Qb0+fnzTcvOiMNAbHMiqkirs4anHX33MKL2gR/3dp8ca9hhWWXZz
|
|
|
|
Mkk2FK9sC/ord9F6mTtvTiOSDzpiEhb94uTxXqBhIbsrGXCUUd0QQN5s2dmW2MfS
|
|
|
|
M35KeSv2rwDGzC1+Qf3MhHGIZDqoQwuZEzM5yHHafCatAbZd2sjaFWegg0r2ca7a
|
|
|
|
eZkZFj3ZuDYXJFnL82guOASh7rElWO2Ys7ncXAKnaV3WkkF+JDv/CUHr+Q/h6Ae5
|
|
|
|
qEvgubTCVSYHzRP37XJItlcdywTIcTY+t6jymmyEBJ66LmUoD47gt/vDUSbhT6Oa
|
|
|
|
GlcZ+MZGlUnPOSq4YknOgwKH8izboY4UgVCrmXvlaZYQhZemNDkVbpYVDf+s6cPf
|
|
|
|
tJwVoZf+qf2SsRTUsI10isoIzCyGw2ie8kmipdP434Z/99uVU3zxD6raNDlyp33q
|
|
|
|
FWMgpr2JU6NVAla7N51g7Jk8VjIIn7SvCYyWkmvv4kLB1UHl3NFqYb9YuIZUaDyt
|
|
|
|
j/NMcKMLLOaEorRZ2N2mDNoihMxMf8J3J9APnzUigAtaalGKNOrd2Fom5OVADePv
|
|
|
|
Tb5sg1uVQzfcpFrjIlLVh+2cekX0JM84phbMpHmm5vCjjfYvUvcMy0clCf0x3jz6
|
|
|
|
LZf5Fzc8xbZmpse5OnOrsDLCNh+SlcYOzsagSZq4TgvSeI9Tr4lv48dLJHCCcYKL
|
|
|
|
eymS9nhlCFuuHbi7zI7edcI49wKUW1Sj+kvKq3LMIEkMlgzqGKA6JqSVxHP51VH5
|
|
|
|
FqV4aKq70H6dNJ43bLVRPhtF5Bip5P7k/6KIsGTPUd54PHey+DuWRjitfheL0G2w
|
|
|
|
GF/qoZyC1mbqdtyyeWgHtVbJVUORmpbNnXOII9duEqBUNDiO9VSZNn/8h/VsYeAB
|
|
|
|
xryZaRDVmtMuf/OZBQ==
|
|
|
|
-----END ENCRYPTED PRIVATE KEY-----';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-06-13 17:39:12 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPrivateKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSavePKCS8PrivateKey()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-06-13 17:39:12 +00:00
|
|
|
|
|
|
|
$key = '-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
|
|
|
|
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
|
|
|
|
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
|
|
|
|
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
|
|
|
|
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
|
|
|
|
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
|
|
|
|
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
|
|
|
|
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
|
|
|
|
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
|
|
|
|
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
|
|
|
|
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
|
|
|
|
-----END RSA PRIVATE KEY-----';
|
|
|
|
$rsa->setPassword('password');
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-06-13 17:39:12 +00:00
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$key = $rsa->getPrivateKey('PKCS8');
|
2014-06-13 17:39:12 +00:00
|
|
|
$this->assertInternalType('string', $key);
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-06-13 17:39:12 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 15:30:32 +00:00
|
|
|
public function testPubKey1()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-04-17 15:30:32 +00:00
|
|
|
|
|
|
|
$key = '-----BEGIN RSA PUBLIC KEY-----
|
|
|
|
MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa
|
|
|
|
D1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw
|
|
|
|
luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB
|
|
|
|
o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV
|
|
|
|
gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH
|
|
|
|
Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
|
|
|
|
-----END RSA PUBLIC KEY-----';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPublicKey());
|
|
|
|
$this->assertFalse($rsa->getPrivateKey());
|
2014-04-17 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPubKey2()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-04-17 15:30:32 +00:00
|
|
|
|
|
|
|
$key = '-----BEGIN PUBLIC KEY-----
|
|
|
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA61BjmfXGEvWmegnBGSuS
|
|
|
|
+rU9soUg2FnODva32D1AqhwdziwHINFaD1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBS
|
|
|
|
EVCgJjtHAGZIm5GL/KA86KDp/CwDFMSwluowcXwDwoyinmeOY9eKyh6aY72xJh7n
|
|
|
|
oLBBq1N0bWi1e2i+83txOCg4yV2oVXhBo8pYEJ8LT3el6Smxol3C1oFMVdwPgc0v
|
|
|
|
Tl25XucMcG/ALE/KNY6pqC2AQ6R2ERlVgPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeu
|
|
|
|
lmCpGSynXNcpZ/06+vofGi/2MlpQZNhHAo8eayMp6FcvNucIpUndo1X8dKMv3Y26
|
|
|
|
ZQIDAQAB
|
|
|
|
-----END PUBLIC KEY-----';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPublicKey());
|
|
|
|
$this->assertFalse($rsa->getPrivateKey());
|
2014-04-17 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 16:41:08 +00:00
|
|
|
public function testSSHPubKey()
|
2014-04-17 15:30:32 +00:00
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-04-17 15:30:32 +00:00
|
|
|
|
|
|
|
$key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4e' .
|
|
|
|
'CZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMS' .
|
|
|
|
'GkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZw== ' .
|
|
|
|
'phpseclib-generated-key';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertInternalType('string', $rsa->getPublicKey());
|
|
|
|
$this->assertFalse($rsa->getPrivateKey());
|
2014-04-17 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2015-05-04 07:21:37 +00:00
|
|
|
public function testSSHPubKeyFingerprint()
|
|
|
|
{
|
|
|
|
$rsa = new RSA();
|
|
|
|
|
|
|
|
$key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD9K+ebJRMN10kGanhi6kDz6EYFqZttZWZh0'.
|
|
|
|
'YoEbIbbere9N2Yvfc7oIoCTHYowhXND9WSJaIs1E4bx0085CZnofWaqf4NbZTzAh18iZup08ec'.
|
|
|
|
'COB5gJVS1efpgVSviDF2L7jxMsBVoOBfqsmA8m0RwDDVezyWvw4y+STSuVzu2jI8EfwN7ZFGC6'.
|
|
|
|
'Yo8m/Z94qIGzqPYGKJLuCeidB0TnUE0ZtzOJTiOc/WoTm/NOpCdfQZEJggd1MOTi+QUnqRu4Wu'.
|
|
|
|
'b6wYtY/q/WtUFr3nK+x0lgOtokhnJfRR/6fnmC1CztPnIT4BWK81VGKWONAxuhMyQ5XChyu6S9'.
|
|
|
|
'mWG5tUlUI/5';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2015-05-04 07:21:37 +00:00
|
|
|
$this->assertSame($rsa->getPublicKeyFingerprint('md5'), 'bd:2c:2f:31:b9:ef:b8:f8:ad:fc:40:a6:94:4f:28:82');
|
|
|
|
$this->assertSame($rsa->getPublicKeyFingerprint('sha256'), 'N9sV2uSNZEe8TITODku0pRI27l+Zk0IY0TrRTw3ozwM');
|
|
|
|
}
|
|
|
|
|
2014-04-17 15:30:32 +00:00
|
|
|
public function testSetPrivate()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-04-17 15:30:32 +00:00
|
|
|
|
|
|
|
$key = '-----BEGIN RSA PUBLIC KEY-----
|
|
|
|
MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa
|
|
|
|
D1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw
|
|
|
|
luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB
|
|
|
|
o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV
|
|
|
|
gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH
|
|
|
|
Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
|
|
|
|
-----END RSA PUBLIC KEY-----';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertTrue($rsa->load($key));
|
2014-04-18 16:41:08 +00:00
|
|
|
$this->assertTrue($rsa->setPrivateKey());
|
|
|
|
$this->assertGreaterThanOrEqual(1, strlen("$rsa"));
|
|
|
|
$this->assertFalse($rsa->getPublicKey());
|
2014-02-15 18:57:49 +00:00
|
|
|
}
|
2014-09-09 03:26:14 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-29 16:07:17 +00:00
|
|
|
* make phpseclib generated XML keys be unsigned. this may need to be reverted
|
|
|
|
* if it is later learned that XML keys are, in fact, supposed to be signed
|
|
|
|
* @group github468
|
|
|
|
*/
|
2014-09-09 03:26:14 +00:00
|
|
|
public function testUnsignedXML()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-09-09 03:26:14 +00:00
|
|
|
|
|
|
|
$key = '<RSAKeyValue>
|
2014-09-09 05:28:38 +00:00
|
|
|
<Modulus>v5OxcEgxPUfa701NpxnScCmlRkbwSGBiTWobHkIWZEB+AlRTHaVoZg/D8l6YzR7VdQidG6gF+nuUMjY75dBXgY/XcyVq0Hccf1jTfgARuNuq4GGG3hnCJVi2QsOgcf9R7TeXn+p1RKIhjQoWCiEQeEBTotNbJhcabNcPGSEJw+s=</Modulus>
|
|
|
|
<Exponent>AQAB</Exponent>
|
2014-09-09 03:26:14 +00:00
|
|
|
</RSAKeyValue>';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$rsa->load($key);
|
2014-09-09 05:28:38 +00:00
|
|
|
$rsa->setPublicKey();
|
2015-10-01 15:15:58 +00:00
|
|
|
$newkey = $rsa->getPublicKey('XML');
|
2014-09-09 03:26:14 +00:00
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$this->assertSame(strtolower(preg_replace('#\s#', '', $key)), strtolower(preg_replace('#\s#', '', $newkey)));
|
2014-09-09 03:26:14 +00:00
|
|
|
}
|
2014-09-09 05:28:38 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-29 16:07:17 +00:00
|
|
|
* @group github468
|
|
|
|
*/
|
2014-09-09 05:28:38 +00:00
|
|
|
public function testSignedPKCS1()
|
|
|
|
{
|
2014-12-17 00:16:54 +00:00
|
|
|
$rsa = new RSA();
|
2014-09-09 05:28:38 +00:00
|
|
|
|
|
|
|
$key = '-----BEGIN PUBLIC KEY-----
|
|
|
|
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/k7FwSDE9R9rvTU2nGdJwKaVG
|
|
|
|
RvBIYGJNahseQhZkQH4CVFMdpWhmD8PyXpjNHtV1CJ0bqAX6e5QyNjvl0FeBj9dz
|
|
|
|
JWrQdxx/WNN+ABG426rgYYbeGcIlWLZCw6Bx/1HtN5ef6nVEoiGNChYKIRB4QFOi
|
|
|
|
01smFxps1w8ZIQnD6wIDAQAB
|
|
|
|
-----END PUBLIC KEY-----';
|
|
|
|
|
2015-10-01 15:15:58 +00:00
|
|
|
$rsa->load($key);
|
2014-09-09 05:28:38 +00:00
|
|
|
$rsa->setPublicKey();
|
|
|
|
$newkey = $rsa->getPublicKey();
|
|
|
|
|
2014-09-09 05:43:28 +00:00
|
|
|
$this->assertSame(preg_replace('#\s#', '', $key), preg_replace('#\s#', '', $newkey));
|
2014-09-09 05:28:38 +00:00
|
|
|
}
|
2014-01-18 17:29:25 +00:00
|
|
|
}
|