Search in sources :

Example 26 with Resource

use of io.churchkey.Resource in project churchkey by tomitribe.

the class BeginPrivateKeyTest method javaEcPrivateKeyPrime256v1.

@Test
public void javaEcPrivateKeyPrime256v1() throws Exception {
    final Resource resources = Resource.resource(this.getClass().getSimpleName());
    final byte[] bytes = resources.bytes("java-ecprivatekey-prime256v1.pem");
    final Key key = Keys.decode(bytes);
    final ECPrivateKey privateKey = (ECPrivateKey) key.getKey();
    assertBigInteger("s", privateKey.getS(), "" + "30C3DEC6AAB43F2230DACF40BFF081BAFC5658DE48716D4C9EE406B57112BE29");
    final ECFieldFp field = (ECFieldFp) privateKey.getParams().getCurve().getField();
    assertBigInteger("fp", field.getP(), "" + "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
    assertBigInteger("a", privateKey.getParams().getCurve().getA(), "" + "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
    assertBigInteger("b", privateKey.getParams().getCurve().getB(), "" + "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
    assertBigInteger("x", privateKey.getParams().getGenerator().getAffineX(), "" + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296");
    assertBigInteger("y", privateKey.getParams().getGenerator().getAffineY(), "" + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");
    assertBigInteger("n", privateKey.getParams().getOrder(), "" + "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
    assertEquals(1, privateKey.getParams().getCofactor());
}
Also used : ECPrivateKey(java.security.interfaces.ECPrivateKey) ECFieldFp(java.security.spec.ECFieldFp) Resource(io.churchkey.Resource) Key(io.churchkey.Key) ECPrivateKey(java.security.interfaces.ECPrivateKey) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Test(org.junit.Test)

Example 27 with Resource

use of io.churchkey.Resource in project churchkey by tomitribe.

the class BeginRsaPrivateKeyTest method decode.

/**
 * Decode and compare to the DER file parsed by the JVM
 */
@Test
public void decode() throws Exception {
    final Resource resource = Resource.resource("rsa", bits, 256);
    final KeyFactory rsa = KeyFactory.getInstance("RSA");
    final RSAPrivateCrtKey expected = (RSAPrivateCrtKey) rsa.generatePrivate(new PKCS8EncodedKeySpec(resource.bytes("private.pkcs8.der")));
    final byte[] bytes = resource.bytes("private.pkcs1.pem");
    final Key key = Keys.decode(bytes);
    assertEquals(Key.Algorithm.RSA, key.getAlgorithm());
    assertEquals(Key.Format.PEM, key.getFormat());
    assertEquals(Key.Type.PRIVATE, key.getType());
    final RSAPrivateCrtKey actual = (RSAPrivateCrtKey) key.getKey();
    KeyAsserts.assertRsaPrivateKey(expected, actual);
}
Also used : RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) Resource(io.churchkey.Resource) KeyFactory(java.security.KeyFactory) Key(io.churchkey.Key) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Test(org.junit.Test)

Example 28 with Resource

use of io.churchkey.Resource in project churchkey by tomitribe.

the class BeginRsaPrivateKeyTest method publicKey.

@Test
public void publicKey() throws Exception {
    final Resource resource = Resource.resource("rsa", bits, 256);
    final byte[] bytes = resource.bytes("private.pkcs1.pem");
    final Key key = Keys.decode(bytes).getPublicKey();
    assertNotNull(key);
    assertEquals(Key.Algorithm.RSA, key.getAlgorithm());
    assertEquals(Key.Format.PEM, key.getFormat());
    assertEquals(Key.Type.PUBLIC, key.getType());
}
Also used : Resource(io.churchkey.Resource) Key(io.churchkey.Key) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Test(org.junit.Test)

Example 29 with Resource

use of io.churchkey.Resource in project churchkey by tomitribe.

the class BeginRsaPublicKeyTest method testKeysDecode1024.

@Test
public void testKeysDecode1024() throws Exception {
    final Decoder decoder = Keys::decode;
    final Resource resource = Resource.resource("rsa", 1024, 256);
    assertDecode(decoder, resource);
}
Also used : Resource(io.churchkey.Resource) Decoder(io.churchkey.Decoder) Test(org.junit.Test)

Example 30 with Resource

use of io.churchkey.Resource in project churchkey by tomitribe.

the class BeginRsaPublicKeyTest method testKeysDecode2048.

@Test
public void testKeysDecode2048() throws Exception {
    final Decoder decoder = Keys::decode;
    final Resource resource = Resource.resource("rsa", 2048, 256);
    assertDecode(decoder, resource);
}
Also used : Resource(io.churchkey.Resource) Decoder(io.churchkey.Decoder) Test(org.junit.Test)

Aggregations

Resource (io.churchkey.Resource)45 Test (org.junit.Test)36 Key (io.churchkey.Key)30 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)20 Decoder (io.churchkey.Decoder)19 RSAPublicKey (java.security.interfaces.RSAPublicKey)15 KeyFactory (java.security.KeyFactory)14 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)9 DSAPublicKey (java.security.interfaces.DSAPublicKey)8 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)6 ECPrivateKey (java.security.interfaces.ECPrivateKey)6 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)5 Ignore (org.junit.Ignore)5 ECPublicKey (java.security.interfaces.ECPublicKey)4 ECFieldFp (java.security.spec.ECFieldFp)3 DerWriter (io.churchkey.asn1.DerWriter)2 Asn1Object (io.churchkey.asn1.Asn1Object)1 DerParser (io.churchkey.asn1.DerParser)1 Pem (io.churchkey.util.Pem)1 BigInteger (java.math.BigInteger)1