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