2013-12-27 16:41:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-02-15 18:57:49 +00:00
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
|
|
|
* @copyright MMXIII Jim Wigginton
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2013-12-27 16:41:07 +00:00
|
|
|
*/
|
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
require_once 'Crypt/RSA.php' ;
|
|
|
|
|
2013-12-27 16:41:07 +00:00
|
|
|
class Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
|
|
|
|
{
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testBadKey()
|
|
|
|
{
|
|
|
|
$rsa = new Crypt_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
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$this->assertFalse($rsa->loadKey($key));
|
|
|
|
}
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testPKCS1Key()
|
|
|
|
{
|
|
|
|
$rsa = new Crypt_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
|
|
|
$this->assertTrue($rsa->loadKey($key));
|
|
|
|
}
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testPKCS1SpacesKey()
|
|
|
|
{
|
|
|
|
$rsa = new Crypt_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
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$this->assertTrue($rsa->loadKey($key));
|
|
|
|
}
|
2013-12-27 16:41:07 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
public function testPKCS1NoHeaderKey()
|
|
|
|
{
|
|
|
|
$rsa = new Crypt_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=';
|
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$this->assertTrue($rsa->loadKey($key));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPKCS1NoWhitespaceNoHeaderKey()
|
|
|
|
{
|
|
|
|
$rsa = new Crypt_RSA();
|
|
|
|
|
|
|
|
$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=';
|
|
|
|
$this->assertTrue($rsa->loadKey($key));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRawPKCS1Key()
|
|
|
|
{
|
|
|
|
$rsa = new Crypt_RSA();
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->assertTrue($rsa->loadKey($key));
|
|
|
|
}
|
2014-01-18 17:29:25 +00:00
|
|
|
}
|