Search in sources :

Example 11 with KeyPair

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;
}
Also used : RealmInfo(org.forgerock.openam.core.RealmInfo) KeyPair(java.security.KeyPair) PublicKey(java.security.PublicKey)

Example 12 with KeyPair

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;
}
Also used : KeyPair(java.security.KeyPair)

Example 13 with 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;
    }
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) PublicKey(java.security.PublicKey)

Example 14 with KeyPair

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;
}
Also used : KeyPair(java.security.KeyPair) X509V3CertificateGenerator(com.android.org.bouncycastle.x509.X509V3CertificateGenerator) X509Certificate(java.security.cert.X509Certificate)

Example 15 with KeyPair

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);
}
Also used : KeyPair(java.security.KeyPair)

Aggregations

KeyPair (java.security.KeyPair)903 KeyPairGenerator (java.security.KeyPairGenerator)345 Test (org.junit.Test)235 PrivateKey (java.security.PrivateKey)189 X509Certificate (java.security.cert.X509Certificate)185 PublicKey (java.security.PublicKey)167 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)127 IOException (java.io.IOException)121 BigInteger (java.math.BigInteger)87 Date (java.util.Date)78 SecureRandom (java.security.SecureRandom)75 KeyStore (java.security.KeyStore)74 GeneralSecurityException (java.security.GeneralSecurityException)63 RSAPublicKey (java.security.interfaces.RSAPublicKey)55 X500Principal (javax.security.auth.x500.X500Principal)53 File (java.io.File)52 KeyFactory (java.security.KeyFactory)52 ECPrivateKey (java.security.interfaces.ECPrivateKey)52 ECPublicKey (java.security.interfaces.ECPublicKey)52 InvalidKeyException (java.security.InvalidKeyException)40