mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-04 10:38:12 +01:00
PublicKeyLoader: add loadPublic, loadPrivate and loadParameters
This commit is contained in:
parent
a18b86ae26
commit
3bddf4d962
@ -180,6 +180,55 @@ abstract class AsymmetricKey
|
||||
$new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a private key
|
||||
*
|
||||
* @return PrivateKey
|
||||
* @access public
|
||||
* @param string|array $key
|
||||
* @param string $password optional
|
||||
*/
|
||||
public function loadPrivate($key, $password = '')
|
||||
{
|
||||
$key = self::load($key, $password);
|
||||
if (!$key instanceof PrivateKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a private key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a public key
|
||||
*
|
||||
* @return PublicKey
|
||||
* @access public
|
||||
* @param string|array $key
|
||||
*/
|
||||
public function loadPublic($key)
|
||||
{
|
||||
$key = self::load($key);
|
||||
if (!$key instanceof PublicKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a public key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads parameters
|
||||
*
|
||||
* @return AsymmetricKey
|
||||
* @access public
|
||||
* @param string|array $key
|
||||
*/
|
||||
public function loadParameters($key)
|
||||
{
|
||||
$key = self::load($key);
|
||||
if (!$key instanceof PrivateKey && !$key instanceof PublicKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a parameter');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the key, assuming a specific format
|
||||
*
|
||||
@ -212,6 +261,58 @@ abstract class AsymmetricKey
|
||||
$new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a private key
|
||||
*
|
||||
* @return PrivateKey
|
||||
* @access public
|
||||
* @param string $type
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
*/
|
||||
public function loadPrivateFormat($type, $key, $password = false)
|
||||
{
|
||||
$key = self::loadFormat($type, $key, $password);
|
||||
if (!$key instanceof PrivateKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a private key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a public key
|
||||
*
|
||||
* @return PublicKey
|
||||
* @access public
|
||||
* @param string $type
|
||||
* @param string $key
|
||||
*/
|
||||
public function loadPublicFormat($type, $key)
|
||||
{
|
||||
$key = self::loadFormat($type, $key);
|
||||
if (!$key instanceof PublicKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a public key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads parameters
|
||||
*
|
||||
* @return AsymmetricKey
|
||||
* @access public
|
||||
* @param string $type
|
||||
* @param string|array $key
|
||||
*/
|
||||
public function loadParametersFormat($type, $key)
|
||||
{
|
||||
$key = self::loadFormat($type, $key);
|
||||
if (!$key instanceof PrivateKey && !$key instanceof PublicKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a parameter');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Plugin
|
||||
*
|
||||
|
@ -16,6 +16,8 @@
|
||||
namespace phpseclib3\Crypt;
|
||||
|
||||
use phpseclib3\Crypt\Common\AsymmetricKey;
|
||||
use phpseclib3\Crypt\Common\PublicKey;
|
||||
use phpseclib3\Crypt\Common\PrivateKey;
|
||||
use phpseclib3\Exception\NoKeyLoadedException;
|
||||
use phpseclib3\File\X509;
|
||||
|
||||
@ -61,4 +63,53 @@ abstract class PublicKeyLoader
|
||||
|
||||
throw new NoKeyLoadedException('Unable to read key');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a private key
|
||||
*
|
||||
* @return PrivateKey
|
||||
* @access public
|
||||
* @param string|array $key
|
||||
* @param string $password optional
|
||||
*/
|
||||
public function loadPrivate($key, $password = false)
|
||||
{
|
||||
$key = self::load($key, $password);
|
||||
if (!$key instanceof PrivateKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a private key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a public key
|
||||
*
|
||||
* @return PublicKey
|
||||
* @access public
|
||||
* @param string|array $key
|
||||
*/
|
||||
public function loadPublic($key)
|
||||
{
|
||||
$key = self::load($key);
|
||||
if (!$key instanceof PublicKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a public key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads parameters
|
||||
*
|
||||
* @return AsymmetricKey
|
||||
* @access public
|
||||
* @param string|array $key
|
||||
*/
|
||||
public function loadParameters($key)
|
||||
{
|
||||
$key = self::load($key);
|
||||
if (!$key instanceof PrivateKey && !$key instanceof PublicKey) {
|
||||
throw new NoKeyLoadedException('The key that was loaded was not a parameter');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user