depage-fs
Toggle main menu visibility
Loading...
Searching...
No Matches
PrivateSshKey.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Depage\Fs;
4
5
use Depage\Fs\Exceptions\FsException;
6
7
class
PrivateSshKey
extends
PublicSshKey
8
{
9
protected
function
parse
($keyString)
10
{
11
$details = $this->
openssl_pkey_get_private
($keyString);
12
13
if
($details ===
false
) {
14
throw
new
FsException
(
'Invalid SSH private key format (PEM format required).'
);
15
}
16
17
return
$details;
18
}
19
22
public
function
extractPublicKey
($tmpDir)
23
{
24
$details = openssl_pkey_get_details($this->key);
25
26
if
(isset($details[
'rsa'
])) {
27
$buffer = pack(
'N'
, 7) .
'ssh-rsa'
.
28
$this->
sshEncodeBuffer
($details[
'rsa'
][
'e'
]) .
29
$this->
sshEncodeBuffer
($details[
'rsa'
][
'n'
]);
30
}
else
{
31
throw
new
FsException
(
'Currently public key generation is only supported for RSA keys.'
);
32
}
33
$publicKeyString =
'ssh-rsa '
. base64_encode($buffer) .
"\n"
;
34
35
return
new
PublicSshKey
($publicKeyString, $tmpDir);
36
}
37
40
protected
function
sshEncodeBuffer
($buffer)
41
{
42
$len = strlen($buffer);
43
if
(ord($buffer[0]) & 0x80) {
44
$len++;
45
$buffer =
"\x00"
. $buffer;
46
}
47
48
return
pack(
'Na*'
, $len, $buffer);
49
}
50
54
protected
function
openssl_pkey_get_private
(
$key
, $passphrase =
''
)
55
{
56
return \openssl_pkey_get_private(
$key
, $passphrase);
57
}
58
}
59
60
/* vim:set ft=php sw=4 sts=4 fdm=marker : */
Depage\Fs\Exceptions\FsException
Definition
FsException.php:5
Depage\Fs\PrivateSshKey
Definition
PrivateSshKey.php:8
Depage\Fs\PrivateSshKey\openssl_pkey_get_private
openssl_pkey_get_private($key, $passphrase='')
hook, allows overriding openssl_pkey_get_private
Definition
PrivateSshKey.php:54
Depage\Fs\PrivateSshKey\sshEncodeBuffer
sshEncodeBuffer($buffer)
from http://stackoverflow.com/questions/5524121/converting-an-openssl-generated-rsa-public-key-to-ope...
Definition
PrivateSshKey.php:40
Depage\Fs\PrivateSshKey\parse
parse($keyString)
Definition
PrivateSshKey.php:9
Depage\Fs\PrivateSshKey\extractPublicKey
extractPublicKey($tmpDir)
from http://stackoverflow.com/questions/5524121/converting-an-openssl-generated-rsa-public-key-to-ope...
Definition
PrivateSshKey.php:22
Depage\Fs\PublicSshKey
Definition
PublicSshKey.php:6
Depage\Fs\PublicSshKey\$key
$key
Definition
PublicSshKey.php:7
PrivateSshKey.php
Generated on
for depage-fs by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net