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());
}
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());
}
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);
}
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);
}
}
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());
}
Aggregations