troia-studio/ssh-key-validator

SSH Public Key validator

v1.0.0 2023-08-03 13:55 UTC

This package is auto-updated.

Last update: 2024-11-03 16:38:08 UTC


README

Usage

To install latest version of troia-studio/ssh-key-validator use Composer.

composer require troia-studio/ssh-key-validator

Supported Keys

  • DSS
  • ECDSA (and SK)
  • ED255 (and SK)
  • RSA

Examples

Validation

Use all validators

use TroiaStudio\SshKeyValidator\KeyValidator;

$keyValidator = KeyValidator::createAll();

$isValid = $keyValidator->validate('ssh-ed25519 BOOOM'); // return bool

Use specifics validators

use TroiaStudio\SshKeyValidator\KeyValidator;
use TroiaStudio\SshKeyValidator\Validators\RsaValidator;
use TroiaStudio\SshKeyValidator\Validators\Ed25519Validator;

$validators = [
    new RsaValidator(),
    new Ed25519Validator(),
];

$keyValidator = new KeyValidator($validators);
$isValid = $keyValidator->validate('ssh-ed25519 BOOOM'); // return bool

Create Key object

Key object contains information like prefix, type, key, and comment. When we before create, factory will check if key is valid.

use TroiaStudio\SshKeyValidator\KeyFactory;

$validators = [
    new RsaValidator(),
    new Ed25519Validator(),
];

$key = KeyFactory::create('ssh-ed25519 BOOOM'));
// Or
$key = KeyFactory::create('ssh-ed25519 BOOOM', $validators));