Search in sources :

Example 1 with Decoder

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

the class BeginPrivateKeyTest method testDecode1024.

@Test
public void testDecode1024() throws Exception {
    final Decoder decoder = new PemParser.PemDecoder()::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 2 with Decoder

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

the class BeginRsaPublicKeyTest method testDecode2048.

@Test
public void testDecode2048() throws Exception {
    final Decoder decoder = new PemParser.PemDecoder()::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)

Example 3 with Decoder

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

the class OpenSSHPrivateKeyTest method rsa.

@Test
public void rsa() throws Exception {
    final Decoder decoder = Keys::decode;
    final Resource resource = Resource.resource("opensshrsa", 2048, 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.openssh");
    final Key key = decoder.decode(bytes);
    assertEquals(Key.Algorithm.RSA, key.getAlgorithm());
    assertEquals(Key.Format.OPENSSH, 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) Decoder(io.churchkey.Decoder) KeyFactory(java.security.KeyFactory) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) Key(io.churchkey.Key) ECPrivateKey(java.security.interfaces.ECPrivateKey) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Test(org.junit.Test)

Example 4 with Decoder

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

the class JwtRsaPublicKeyEncodeTest method testKeysDecode2048.

@Test
public void testKeysDecode2048() throws Exception {
    final Decoder decoder = Keys::decode;
    final Resource resource = Resource.resource("rsa", 2048, 256);
    final KeyFactory rsa = KeyFactory.getInstance("RSA");
    final RSAPublicKey expected = (RSAPublicKey) rsa.generatePublic(new X509EncodedKeySpec(resource.bytes("public.pkcs8.der")));
    final Key key = decoder.decode(resource.bytes("public.jwk"));
    assertKey(expected, key);
    final byte[] encode = Keys.encode(key);
    JsonAsserts.assertJson(new String(resource.bytes("public.jwk")), new String(encode));
    assertKey(expected, Keys.decode(encode));
}
Also used : RSAPublicKey(java.security.interfaces.RSAPublicKey) Resource(io.churchkey.Resource) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) Decoder(io.churchkey.Decoder) KeyFactory(java.security.KeyFactory) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(io.churchkey.Key) Test(org.junit.Test)

Example 5 with Decoder

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

the class JwtRsaPublicKeyEncodeTest method testKeysDecode1024.

@Test
public void testKeysDecode1024() throws Exception {
    final Decoder decoder = Keys::decode;
    final Resource resource = Resource.resource("rsa", 1024, 256);
    final KeyFactory rsa = KeyFactory.getInstance("RSA");
    final RSAPublicKey expected = (RSAPublicKey) rsa.generatePublic(new X509EncodedKeySpec(resource.bytes("public.pkcs8.der")));
    final Key key = decoder.decode(resource.bytes("public.jwk"));
    assertKey(expected, key);
    final byte[] encode = Keys.encode(key);
    JsonAsserts.assertJson(new String(resource.bytes("public.jwk")), new String(encode));
    assertKey(expected, Keys.decode(encode));
}
Also used : RSAPublicKey(java.security.interfaces.RSAPublicKey) Resource(io.churchkey.Resource) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) Decoder(io.churchkey.Decoder) KeyFactory(java.security.KeyFactory) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(io.churchkey.Key) Test(org.junit.Test)

Aggregations

Decoder (io.churchkey.Decoder)19 Resource (io.churchkey.Resource)19 Test (org.junit.Test)19 Key (io.churchkey.Key)7 KeyFactory (java.security.KeyFactory)5 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)5 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)3 ECPrivateKey (java.security.interfaces.ECPrivateKey)3 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)3 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)2