class SshGenerator implements CredentialGenerator<SshCredentialValue> {

  @Override
  public SshCredentialValue generateCredential(final GenerationParameters p) {
    final SshGenerationParameters params = (SshGenerationParameters) p;
    try {
      final KeyPair keyPair = keyGenerator.generateKeyPair(params.getKeyLength());
      final String sshComment = params.getSshComment();
      final String sshCommentMessage = StringUtils.isEmpty(sshComment) ? "" : " " + sshComment;

      final String publicKey =
        CertificateFormatter.derOf((RSAPublicKey) keyPair.getPublic()) + sshCommentMessage;
      final String privateKey = CertificateFormatter.pemOf(keyPair.getPrivate());

      return new SshCredentialValue(publicKey, privateKey, null);
    } catch (final Exception e) {
      throw new RuntimeException(e);
    }
  }

  @Autowired public  SshGenerator(final RsaKeyPairGenerator keyGenerator);

}