Search in sources :

Example 66 with KeyPair

use of java.security.KeyPair in project j2objc by google.

the class KeyPairTest method testGetPrivate01.

/**
     * Test #1 for <code>getPrivate()</code> method<br>
     * Assertion: returns private key (<code>null</code> in this case)
     */
public final void testGetPrivate01() {
    KeyPair kp = new KeyPair(null, null);
    assertNull(kp.getPrivate());
}
Also used : KeyPair(java.security.KeyPair)

Example 67 with KeyPair

use of java.security.KeyPair in project j2objc by google.

the class KeyPairTest method testGetPublic01.

/**
     * Test #1 for <code>getPublic()</code> method<br>
     * Assertion: returns public key (<code>null</code> in this case)
     */
public final void testGetPublic01() {
    KeyPair kp = new KeyPair(null, null);
    assertNull(kp.getPublic());
}
Also used : KeyPair(java.security.KeyPair)

Example 68 with KeyPair

use of java.security.KeyPair in project j2objc by google.

the class KeyPairTest method testKeyPair01.

/**
     * Test #1 for <code>KeyPair(PublicKey, PrivateKey)</code> constructor<br>
     * Assertion: creates new <code>KeyPair</code> instance using valid
     * parameters (both <code>null</code>)
     */
public final void testKeyPair01() {
    Object kp = new KeyPair(null, null);
    assertTrue(kp instanceof KeyPair);
    kp = new KeyPair(null, TestKeyPair.getPrivate());
    assertTrue(kp instanceof KeyPair);
    kp = new KeyPair(TestKeyPair.getPublic(), null);
    assertTrue(kp instanceof KeyPair);
}
Also used : KeyPair(java.security.KeyPair)

Example 69 with KeyPair

use of java.security.KeyPair in project wycheproof by google.

the class EcKeyTest method testDefaultKeyGeneration.

/**
   * Checks that the default key size for ECDSA is up to date.
   * The test uses NIST SP 800-57 part1 revision 4, Table 2, page 53
   * http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf
   * for the minimal key size of EC keys.
   * Nist recommends a minimal security strength of 112 bits for the time until 2030.
   * To achieve this security strength EC keys of at least 224 bits are required.
   */
public void testDefaultKeyGeneration() throws Exception {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
    KeyPair keyPair = keyGen.generateKeyPair();
    ECPublicKey pub = (ECPublicKey) keyPair.getPublic();
    int keySize = EcUtil.fieldSizeInBits(pub.getParams().getCurve());
    if (keySize < 224) {
        fail("Expected a default key size of at least 224 bits. Size of generate key is " + keySize);
    }
}
Also used : KeyPair(java.security.KeyPair) ECPublicKey(java.security.interfaces.ECPublicKey) KeyPairGenerator(java.security.KeyPairGenerator) ECPoint(java.security.spec.ECPoint)

Example 70 with KeyPair

use of java.security.KeyPair in project wycheproof by google.

the class EcKeyTest method testEncodedPrivateKey.

public void testEncodedPrivateKey() throws Exception {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
    keyGen.initialize(EcUtil.getNistP256Params());
    KeyPair keyPair = keyGen.generateKeyPair();
    ECPrivateKey priv = (ECPrivateKey) keyPair.getPrivate();
    byte[] encoded = priv.getEncoded();
    System.out.println("Encoded ECPrivateKey:" + TestUtil.bytesToHex(encoded));
    PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(encoded);
    KeyFactory kf = KeyFactory.getInstance("EC");
    ECPrivateKey decoded = (ECPrivateKey) kf.generatePrivate(spec);
    assertEquals(priv.getS(), decoded.getS());
    assertEquals(priv.getParams().getCofactor(), decoded.getParams().getCofactor());
    assertEquals(priv.getParams().getCurve(), decoded.getParams().getCurve());
    assertEquals(priv.getParams().getGenerator(), decoded.getParams().getGenerator());
    assertEquals(priv.getParams().getOrder(), decoded.getParams().getOrder());
}
Also used : ECPrivateKey(java.security.interfaces.ECPrivateKey) KeyPair(java.security.KeyPair) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) KeyPairGenerator(java.security.KeyPairGenerator) KeyFactory(java.security.KeyFactory)

Aggregations

KeyPair (java.security.KeyPair)313 KeyPairGenerator (java.security.KeyPairGenerator)146 X509Certificate (java.security.cert.X509Certificate)61 PrivateKey (java.security.PrivateKey)60 PublicKey (java.security.PublicKey)59 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)36 IOException (java.io.IOException)34 SecureRandom (java.security.SecureRandom)31 Test (org.junit.Test)26 KeyFactory (java.security.KeyFactory)23 KeyStore (java.security.KeyStore)23 Date (java.util.Date)22 BigInteger (java.math.BigInteger)21 Signature (java.security.Signature)19 File (java.io.File)17 Cipher (javax.crypto.Cipher)17 KeyPairGeneratorSpec (android.security.KeyPairGeneratorSpec)16 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)16 RSAPublicKey (java.security.interfaces.RSAPublicKey)16 HashMap (java.util.HashMap)16