use of java.security.KeyPair in project OpenAM by OpenRock.
the class IdTokenClaimGathererTest method mockOAuth2Uris.
private OAuth2UrisFactory<RealmInfo> mockOAuth2Uris() throws NotFoundException, ServerException {
OAuth2UrisFactory<RealmInfo> oAuth2UrisFactory = mock(OAuth2UrisFactory.class);
given(oAuth2UrisFactory.get(oAuth2Request)).willReturn(oAuth2Uris);
PublicKey publicKey = mock(PublicKey.class);
KeyPair keyPair = new KeyPair(publicKey, null);
given(oAuth2ProviderSettings.getServerKeyPair()).willReturn(keyPair);
return oAuth2UrisFactory;
}
use of java.security.KeyPair in project OpenAM by OpenRock.
the class KeyPairProviderImpl method getKeyPair.
@Override
public KeyPair getKeyPair(String algorithm, int keySize) {
CacheKey cacheKey = new CacheKey(algorithm, keySize);
KeyPair keyPair = keyPairCache.get(cacheKey);
if (keyPair == null) {
synchronized (keyPairCache) {
keyPair = keyPairCache.get(cacheKey);
if (keyPair == null) {
keyPair = newKeyPair(algorithm, keySize);
keyPairCache.put(cacheKey, keyPair);
}
}
}
return keyPair;
}
use of java.security.KeyPair in project OpenAM by OpenRock.
the class AMKeyProvider method getKeyPair.
/**
* Return {@link KeyPair} containing {@link PublicKey} and {@link PrivateKey} for the specified certAlias.
*
* @param certAlias Certificate alias name
*
* @return KeyPair which matches the certAlias, return null if the PrivateKey or PublicKey could not be found.
*/
public KeyPair getKeyPair(String certAlias) {
PublicKey publicKey = getPublicKey(certAlias);
PrivateKey privateKey = getPrivateKey(certAlias);
if (publicKey != null && privateKey != null) {
return new KeyPair(publicKey, privateKey);
} else {
return null;
}
}
use of java.security.KeyPair in project android_frameworks_base by ResurrectionRemix.
the class AndroidKeyStoreTest method generateCertificate.
@SuppressWarnings("deprecation")
private static X509Certificate generateCertificate(android.security.KeyStore keyStore, String alias, BigInteger serialNumber, X500Principal subjectDN, Date notBefore, Date notAfter) throws Exception {
final String privateKeyAlias = Credentials.USER_PRIVATE_KEY + alias;
KeyPair keyPair = AndroidKeyStoreProvider.loadAndroidKeyStoreKeyPairFromKeystore(keyStore, privateKeyAlias, KeyStore.UID_SELF);
final X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setPublicKey(keyPair.getPublic());
certGen.setSerialNumber(serialNumber);
certGen.setSubjectDN(subjectDN);
certGen.setIssuerDN(subjectDN);
certGen.setNotBefore(notBefore);
certGen.setNotAfter(notAfter);
certGen.setSignatureAlgorithm("sha1WithRSA");
final X509Certificate cert = certGen.generate(keyPair.getPrivate());
return cert;
}
use of java.security.KeyPair in project android_frameworks_base by ResurrectionRemix.
the class AndroidKeyPairGeneratorTest method testKeyPairGenerator_GenerateKeyPair_Encrypted_Success.
public void testKeyPairGenerator_GenerateKeyPair_Encrypted_Success() throws Exception {
setupPassword();
mGenerator.initialize(new KeyPairGeneratorSpec.Builder(getContext()).setAlias(TEST_ALIAS_1).setSubject(TEST_DN_1).setSerialNumber(TEST_SERIAL_1).setStartDate(NOW).setEndDate(NOW_PLUS_10_YEARS).setEncryptionRequired().build());
final KeyPair pair = mGenerator.generateKeyPair();
assertNotNull("The KeyPair returned should not be null", pair);
assertKeyPairCorrect(pair, TEST_ALIAS_1, "RSA", 2048, null, TEST_DN_1, TEST_SERIAL_1, NOW, NOW_PLUS_10_YEARS);
}
Aggregations