use of java.security.Key in project OpenAM by OpenRock.
the class OpenAMClientRegistration method byJWKs.
private boolean byJWKs(OAuth2Jwt jwt) throws IdRepoException, SSOException, MalformedURLException, FailedToLoadJWKException {
Set<String> set = amIdentity.getAttribute(OAuth2Constants.OAuth2Client.JWKS);
if (set == null || set.isEmpty()) {
throw OAuthProblemException.OAuthError.SERVER_ERROR.handle(Request.getCurrent(), "No Client Bearer JWKs_URI set.");
}
final String jwkSetStr = set.iterator().next();
final JWKSet jwkSet = new JWKSet(JsonValueBuilder.toJsonValue(jwkSetStr));
//0 values as not using for inet comms
final JWKSetParser setParser = new JWKSetParser(0, 0);
final Map<String, Key> jwkMap = setParser.jwkSetToMap(jwkSet);
final Key key = jwkMap.get(jwt.getSignedJwt().getHeader().getKeyId());
return key != null && jwt.isValid(signingManager.newRsaSigningHandler(key));
}
use of java.security.Key in project yyl_example by Relucent.
the class ExportPrivateKey method getPrivateKey.
public static KeyPair getPrivateKey(KeyStore keystore, String alias, char[] password) {
try {
Key key = keystore.getKey(alias, password);
if (key instanceof PrivateKey) {
Certificate cert = keystore.getCertificate(alias);
PublicKey publicKey = cert.getPublicKey();
return new KeyPair(publicKey, (PrivateKey) key);
}
} catch (UnrecoverableKeyException e) {
} catch (NoSuchAlgorithmException e) {
} catch (KeyStoreException e) {
}
return null;
}
use of java.security.Key in project ats-framework by Axway.
the class SslUtils method createKeyStoreFromPemKey.
private static void createKeyStoreFromPemKey(String clientCert, String clientPass, KeyStore store) throws Exception {
try {
// Load CA Chain file
// CertificateFactory cf = CertificateFactory.getInstance("X.509");
// X509Certificate cert = (X509Certificate) cf.generateCertificate(new FileInputStream(caCert));
store.load(null);
// Load client's public and private keys from PKCS12 certificate
KeyStore inputKeyStore = KeyStore.getInstance("PKCS12");
FileInputStream fis = new FileInputStream(clientCert);
char[] nPassword = null;
if ((clientPass == null) || "".equals(clientPass.trim())) {
nPassword = null;
} else {
nPassword = clientPass.toCharArray();
}
inputKeyStore.load(fis, nPassword);
fis.close();
store.load(null, ((clientPass != null) ? clientPass.toCharArray() : null));
Enumeration<String> en = inputKeyStore.aliases();
while (en.hasMoreElements()) {
// we are reading just one certificate.
String keyAlias = en.nextElement();
if (inputKeyStore.isKeyEntry(keyAlias)) {
Key key = inputKeyStore.getKey(keyAlias, nPassword);
Certificate[] certChain = inputKeyStore.getCertificateChain(keyAlias);
store.setKeyEntry("outkey", key, ((clientPass != null) ? clientPass.toCharArray() : null), certChain);
}
}
} catch (Exception e) {
throw new RuntimeException("Error creating keystore from Pem key", e);
}
}
use of java.security.Key in project graylog2-server by Graylog2.
the class PemKeyStoreTest method testBuildKeyStore.
@Test
public void testBuildKeyStore() throws Exception {
final Path certChainFile = Paths.get(Resources.getResource("org/graylog2/shared/security/tls/chain.crt").toURI());
final Path keyFile = Paths.get(Resources.getResource("org/graylog2/shared/security/tls/private.key").toURI());
final KeyStore keyStore = PemKeyStore.buildKeyStore(certChainFile, keyFile, null);
final Certificate[] keys = keyStore.getCertificateChain("key");
assertThat(keys).hasSize(2);
final Key key = keyStore.getKey("key", new char[0]);
assertThat(key.getFormat()).isEqualTo("PKCS#8");
assertThat(key.getEncoded()).isNotEmpty();
}
use of java.security.Key in project async-http-client by AsyncHttpClient.
the class NtlmEngine method lmHash.
/**
* Creates the LM Hash of the user's password.
*
* @param password
* The password.
*
* @return The LM Hash of the given password, used in the calculation of the
* LM Response.
*/
private static byte[] lmHash(final String password) throws NtlmEngineException {
try {
final byte[] oemPassword = password.toUpperCase(Locale.ROOT).getBytes(US_ASCII);
final int length = Math.min(oemPassword.length, 14);
final byte[] keyBytes = new byte[14];
System.arraycopy(oemPassword, 0, keyBytes, 0, length);
final Key lowKey = createDESKey(keyBytes, 0);
final Key highKey = createDESKey(keyBytes, 7);
final Cipher des = Cipher.getInstance("DES/ECB/NoPadding");
des.init(Cipher.ENCRYPT_MODE, lowKey);
final byte[] lowHash = des.doFinal(MAGIC_CONSTANT);
des.init(Cipher.ENCRYPT_MODE, highKey);
final byte[] highHash = des.doFinal(MAGIC_CONSTANT);
final byte[] lmHash = new byte[16];
System.arraycopy(lowHash, 0, lmHash, 0, 8);
System.arraycopy(highHash, 0, lmHash, 8, 8);
return lmHash;
} catch (final Exception e) {
throw new NtlmEngineException(e.getMessage(), e);
}
}
Aggregations