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