Build and configure an in-memory {@link KeyChain}.

@param name the name of the default identity to create
@return an in-memory {@link KeyChain} configured with the name as the
default identity
@throws SecurityException if failed to create mock identity
482630
public static KeyChain configure(final Name name) throws SecurityException {
    PrivateKeyStorage keyStorage = new MemoryPrivateKeyStorage();
    IdentityStorage identityStorage = new MemoryIdentityStorage();
    KeyChain keyChain = new KeyChain(new IdentityManager(identityStorage, keyStorage),
            new SelfVerifyPolicyManager(identityStorage));

    // create keys, certs if necessary
    if (!identityStorage.doesIdentityExist(name)) {
      keyChain.createIdentityAndCertificate(name);
    }

    // set default identity
    keyChain.getIdentityManager().setDefaultIdentity(name);

    return keyChain;
  }
573854
@Help(help = "Generate a new Key in the NFVO")
  public String generateKey(String name) throws SDKException {
    return (String) requestPost("generate", name);
  }
336639
public X509Credential createCredential(X509Certificate[] certs, PrivateKey privateKey, int bits, int lifetime,
        GSIConstants.CertificateType certType) throws GeneralSecurityException {
        return createCredential(certs, privateKey, bits, lifetime, certType, (X509ExtensionSet) null, null);
    }
1197124
public function getKey($name)
    {
        if (strlen($name) === 0) {
            throw new SecurityException('Required name argument was empty', 1334215378);
        }
        $keyPathAndFilename = $this->getKeyPathAndFilename($name);
        if (!file_exists($keyPathAndFilename)) {
            throw new SecurityException(sprintf('The key "%s" does not exist.', $keyPathAndFilename), 1305812921);
        }
        $key = Utility\Files::getFileContents($keyPathAndFilename);
        if ($key === false) {
            throw new SecurityException(sprintf('The key "%s" could not be read.', $keyPathAndFilename), 1334483163);
        }
        if (strlen($key) === 0) {
            throw new SecurityException(sprintf('The key "%s" is empty.', $keyPathAndFilename), 1334483165);
        }
        return $key;
    }
425557
public static Key<String> key(String name) {
    return Key.get(String.class, Flags.named(name));
  }
90889
public static authenticationcertpolicy_binding get(nitro_service service, String name) throws Exception{
		authenticationcertpolicy_binding obj = new authenticationcertpolicy_binding();
		obj.set_name(name);
		authenticationcertpolicy_binding response = (authenticationcertpolicy_binding) obj.get_resource(service);
		return response;
	}
82759
@SuppressWarnings("unchecked")
	public static SSLContext createSSLContext(String trustedNamesGroupKey) throws IOException {
        SSLContext sslContext = null;
        KeyManager[] keyManagers = null;
        Map<String, Object> tlsMap = (Map<String, Object>)ClientConfig.get().getMappedConfig().get(TLS);
        if(tlsMap != null) {
            try {
                // load key store for client certificate if two way ssl is used.
                Boolean loadKeyStore = (Boolean) tlsMap.get(LOAD_KEY_STORE);
                if (loadKeyStore != null && loadKeyStore) {
                    String keyStoreName = (String)tlsMap.get(KEY_STORE);
                    String keyStorePass = (String)ClientConfig.get().getSecretConfig().get(SecretConstants.CLIENT_KEYSTORE_PASS);
                    String keyPass = (String)ClientConfig.get().getSecretConfig().get(SecretConstants.CLIENT_KEY_PASS);
                    KeyStore keyStore = loadKeyStore(keyStoreName, keyStorePass.toCharArray());
                    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    keyManagerFactory.init(keyStore, keyPass.toCharArray());
                    keyManagers = keyManagerFactory.getKeyManagers();
                }
            } catch (NoSuchAlgorithmException | UnrecoverableKeyException | KeyStoreException e) {
                throw new IOException("Unable to initialise KeyManager[]", e);
            }

            TrustManager[] trustManagers = null;
            try {
                // load trust store, this is the server public key certificate
                // first check if javax.net.ssl.trustStore system properties is set. It is only necessary if the server
                // certificate doesn't have the entire chain.
                Boolean loadTrustStore = (Boolean) tlsMap.get(LOAD_TRUST_STORE);
                if (loadTrustStore != null && loadTrustStore) {
                    String trustStoreName = System.getProperty(TRUST_STORE_PROPERTY);
                    String trustStorePass = System.getProperty(TRUST_STORE_PASSWORD_PROPERTY);
                    if (trustStoreName != null && trustStorePass != null) {
                        if(logger.isInfoEnabled()) logger.info("Loading trust store from system property at " + Encode.forJava(trustStoreName));
                    } else {
                        trustStoreName = (String) tlsMap.get(TRUST_STORE);
                        trustStorePass = (String)ClientConfig.get().getSecretConfig().get(SecretConstants.CLIENT_TRUSTSTORE_PASS);
                        if(logger.isInfoEnabled()) logger.info("Loading trust store from config at " + Encode.forJava(trustStoreName));
                    }
                    if (trustStoreName != null && trustStorePass != null) {
                        KeyStore trustStore = loadKeyStore(trustStoreName, trustStorePass.toCharArray());
                        TLSConfig tlsConfig = TLSConfig.create(tlsMap, trustedNamesGroupKey);

                        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                        trustManagerFactory.init(trustStore);
                        trustManagers = ClientX509ExtendedTrustManager.decorate(trustManagerFactory.getTrustManagers(), tlsConfig);
                    }
                }
            } catch (NoSuchAlgorithmException | KeyStoreException e) {
                throw new IOException("Unable to initialise TrustManager[]", e);
            }

            try {
                sslContext = SSLContext.getInstance("TLS");
                sslContext.init(keyManagers, trustManagers, null);
            } catch (NoSuchAlgorithmException | KeyManagementException e) {
                throw new IOException("Unable to create and initialise the SSLContext", e);
            }
        } else {
            logger.error("TLS configuration section is missing in client.yml");
        }

        return sslContext;
    }
297641
public Object getInstance(String name) throws SshException {
		if (supported.containsKey(name)) {
			try {
				return createInstance(name, (Class<?>) supported.get(name));
			} catch (Throwable t) {
				throw new SshException(t.getMessage(),
						SshException.INTERNAL_ERROR);
			}
		}
		throw new SshException(name + " is not supported",
				SshException.UNSUPPORTED_ALGORITHM);
	}
1192523
SamlIdentityProviderConfig build(CredentialResolverAdapter credentialResolver) {
        checkState(entityId != null, "entity ID of the identity provider is not set");

        // Use the entityId as a default key name.
        final Credential signing = credentialResolver.apply(firstNonNull(signingKey, entityId));
        final Credential encryption = credentialResolver.apply(firstNonNull(encryptionKey, entityId));

        return new SamlIdentityProviderConfig(entityId,
                                              signing,
                                              encryption,
                                              ssoEndpoint,
                                              sloReqEndpoint,
                                              sloResEndpoint,
                                              acsEndpoint,
                                              nameIdPolicy);
    }
32144
public X509Credential createCredential(X509Certificate[] certs, PrivateKey privateKey, int bits, int lifetime,
       GSIConstants.DelegationType delegType, X509ExtensionSet extSet, String cnValue) throws GeneralSecurityException {

        X509Certificate[] bcCerts = getX509CertificateObjectChain(certs);

        return createCredential(bcCerts, privateKey, bits, lifetime, decideProxyType(bcCerts[0], delegType), extSet, cnValue);
    }
730521
public String createKeyValuePair(String keyName) {

    final AmazonEC2 amazonEC2 = getEc2Client();

    final CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest().withKeyName(keyName);
    final CreateKeyPairResult createKeyPairResult = amazonEC2.createKeyPair(createKeyPairRequest);
    final KeyPair keyPair = createKeyPairResult.getKeyPair();
    final String material = keyPair.getKeyMaterial();
    LOGGER.info("Created key: " + keyName);
    LOGGER.debug("Created material: " + material);

    return material;
  }
6517
private AuthnRequest createAuthRequest(SamlIdentityProviderConfig idp, String defaultHostname) {
        requireNonNull(idp, "idp");

        final AuthnRequest authnRequest = build(AuthnRequest.DEFAULT_ELEMENT_NAME);

        final Issuer issuer = build(Issuer.DEFAULT_ELEMENT_NAME);
        issuer.setValue(myEntityId);
        authnRequest.setIssuer(issuer);

        authnRequest.setIssueInstant(DateTime.now());
        authnRequest.setDestination(idp.ssoEndpoint().toUriString());
        authnRequest.setID(requestIdManager.newId());

        // The ProtocolBinding attribute is mutually exclusive with the AssertionConsumerServiceIndex attribute
        // and is typically accompanied by the AssertionConsumerServiceURL attribute.
        final SamlPortConfig portConfig = portConfigHolder.config().get();
        final SamlEndpoint acsEndpoint = idp.acsEndpoint()
                                            .orElse(sp.defaultAcsConfig().endpoint());
        authnRequest.setAssertionConsumerServiceURL(acsEndpoint.toUriString(portConfig.scheme().uriText(),
                                                                            defaultHostname,
                                                                            portConfig.port()));
        authnRequest.setProtocolBinding(acsEndpoint.bindingProtocol().urn());

        final SamlNameIdPolicy policy = idp.nameIdPolicy();
        final NameIDPolicy nameIdPolicy = build(NameIDPolicy.DEFAULT_ELEMENT_NAME);
        nameIdPolicy.setFormat(policy.format().urn());
        nameIdPolicy.setAllowCreate(policy.isCreatable());
        authnRequest.setNameIDPolicy(nameIdPolicy);

        final AuthnContextClassRef passwordAuthnCtxRef = build(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
        passwordAuthnCtxRef.setAuthnContextClassRef(AuthnContext.PASSWORD_AUTHN_CTX);

        final RequestedAuthnContext requestedAuthnContext = build(RequestedAuthnContext.DEFAULT_ELEMENT_NAME);
        requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
        requestedAuthnContext.getAuthnContextClassRefs().add(passwordAuthnCtxRef);

        authnRequest.setRequestedAuthnContext(requestedAuthnContext);

        return authnRequest;
    }
361215
ConfiguredCloseableHttpClient buildWithDefaultRequestConfiguration(String name) {
        return createClient(org.apache.http.impl.client.HttpClientBuilder.create(),
                createConnectionManager(createConfiguredRegistry(), name), name);
    }
929368
public static aaapreauthenticationpolicy_binding get(nitro_service service, String name) throws Exception{
		aaapreauthenticationpolicy_binding obj = new aaapreauthenticationpolicy_binding();
		obj.set_name(name);
		aaapreauthenticationpolicy_binding response = (aaapreauthenticationpolicy_binding) obj.get_resource(service);
		return response;
	}
1274765
public static final KeyPair createKeyPair(AlgorithmParameterSpec spec) throws GeneralSecurityException {
		KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM);
	    keyGen.initialize(spec, new SecureRandom());
		return keyGen.generateKeyPair();
	}
632955
public static HeaderTypes create(final String name) {
        if (name == null) {
            throw new IllegalArgumentException("header name may not be null");
        }
        String type = name.trim().toLowerCase(Locale.ENGLISH);
        if (type.length() == 0) {
            throw new IllegalArgumentException("header name may not be empty");
        }
        return new HeaderTypes(name);
    }
306905
public Cache createCache(String name) throws CacheException {
		SynchronizedCacheConfiguration config = new SynchronizedCacheConfiguration();
		return createCache(name, config, Cache.SYN_CACHE);
	}