Search in sources :

Example 1 with Resource

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

the class BeginPrivateKeyRsaTest method opensslRsaPrivateKey.

@Test
public void opensslRsaPrivateKey() throws Exception {
    final Resource resources = Resource.resource(this.getClass().getSimpleName());
    final byte[] bytes = resources.bytes("openssl-rsaprivatekey-3072.pem");
    final Key key = Keys.decode(bytes);
    final RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) key.getKey();
    assertBigInteger("Modulus", privateKey.getModulus(), "" + "98D012342429A5D857A6B742C6CC31C22E518E8AA36AA72824C64B7509C5F44B" + "78EF2CCDDCE31A76AA575003D031B5737BD948DCDC89D012EE4AB42DDD536E02" + "922C991D7A51A231B89CD17FBDEA1F723C1622F214C1A437791C3020C8FE97ED" + "87271CA105720BEC74D0E0153E67D04A3C469A892145D65CECF1BA293F44F1A0" + "D575F161467A41E4A4B14B49EB398965F050D82EF6ED058AB24A63097D7E5BA1" + "442C200825A9FFA55624D6445C9AC9266B0A5F0F2113D1D912FC69935408B461" + "D27630FC6EDC5CEA619D7D3562A147806390502F4503E075910AEDC21F9AA104" + "594051599A48D736C3E3EC0D3CBCE510E4233968E041A9E9229002AE72E98423" + "720094D5788A09CBA0EF5A3AC8E4388FDF99ED5B16B58E782F795640C45F430E" + "222165D2D828FDDF65D85E4666E67041A06E49693C93BB98E3DE47FC332FF78B" + "5894FE677F2F224A14304B1D74C25ECB1B4CE49BC70F61621990B78499A79869" + "10E8F9A24E49B433D49CAA90D6C064204B2721E938EF4A5F1F1332D83120D3C1");
    assertBigInteger("PublicExponent", privateKey.getPublicExponent(), "010001");
    assertBigInteger("PrivateExponent", privateKey.getPrivateExponent(), "" + "47AD311CABE9AD14B0E84E055061EEE4F9FCDF33403B82745DEB74F14CC84132" + "35635A4CA55310D2A04B9C086DDB23152BFE5B22DD7EF6CE2A5F77EC1B684AAD" + "820AD136F66CDBFB1E70D0036EFD260ADB0C370FFD9466866E943E2EE2982883" + "0D65D713E00E0271C2C9469230575967B8A6154E450110EF3D6494C14C1FF686" + "4E19A842CC6004104EFFAA24DDE47B02099AA20C455E1FBF52A97992B5FE52D4" + "6DB994BCBD8DE38F95BC69945F2B6B364DF6EB67994846A1DF39EDFB60EB444F" + "F45D2C5066B621AAC20CF0CECE9897CD475A031968B499EB0844A5031792F208" + "CC287A420A83C9A7F496A9696A32AA14B80DFA7B3B017BC4331E61024EF246A0" + "50B0A02C4226DCEAAD3D5DD02B1056616BBD9E0878B821FD47FC57CE8230E9C9" + "86FA89E1EA645D124F6CFC34B35BCA3AE92C517EA940C052E3976EAAD1F885F7" + "99CFE3538235701929F8FD7B18CB71F8078A198E9F51B52DC1B57C2BAE695F4C" + "C8A78A3C57FBBA4826E127BDD9074D9F04D539430B1482384C95A7751651DA51");
    assertBigInteger("PrimeP", privateKey.getPrimeP(), "" + "CB6ACC527E7BC99315ED3B1669149FE2A39FE135CA3B5F710AAA86A29ABC00DF" + "23AA41D2EA257DE1388490A8139DB1F424F085783F1AC319DFD84F6FCC670DEA" + "181AC1386287DA6918E41E606B357DB323FCDDC486425F45AB516AEFB17D5A8E" + "7D1C10084A807912F24B334FFAD3BDABE4B416E513553F7E33FFBF127525F3DF" + "ACDFBE68A793D2CF2F92D6763B36962DD09B50C7255F2D4CF60F566A602965C6" + "717839B857E4076EB5394FA4424A324B7B226675E8DACF3664E91D9D26ADB76F");
    assertBigInteger("PrimeQ", privateKey.getPrimeQ(), "" + "C050825D5D15DAB86F4D19598221D66FD1EEF286EC28C93D894702396E3BEB08" + "35BDFB2F5F2CF0F88D8C9C62B2E5EF42F889CAAE86DCF5C0A56604DA3FDF1F28" + "BBFE230DF5B41C404D6A3F1AD111E2FCF5FBC8D11A6BF76BFEE554B96C299854" + "997E95145EA2F5CD83615DB72ABEAC221D12049686B8B12C35A9AF093FF5C2E9" + "6628550DAFB989C97DC39A20CB18C4D23EA68244F37FBB1960E7B270948660D2" + "0F192EBE23A23FF9A53931B14FE5911551195E357BC9E2AF597A4C09ECB60FCF");
    assertBigInteger("CrtCoefficient", privateKey.getCrtCoefficient(), "" + "B014825FF34FE6189B6839A39254079F7859026DC047EA8C12A93EEE1ED751A3" + "5EB2CE3FC97922BB7BCB093E7B827CD6DA2AD260F54AC20260845E926BAE9319" + "64D9D34DDBB5DA34A0839D8D845970E326800BAFA5EA0762572729495CA89278" + "57E55AA684E3F57F0001CEF1EEB7BD17D5C2DCA825BDB42DF81CED60351D6268" + "9E89A65EEBCF9EFA0C117FB0463A560A67CBBC4790C7047BCEF0AC3519920B05" + "B08537CEB4EC66A6EF8835CD53BC744F11418CE669AEACF35C219B44BE9504C9");
    assertBigInteger("PrimeExponentP", privateKey.getPrimeExponentP(), "" + "2C52B102A89CC0675437C4D0354551314905E5449B3424AFB4EB433ADB0C6C04" + "32F93E2E7EE67C6F3EA963FBBB8A78E401C886CC94B3781F832ED6E03D61971E" + "92F201780FC01A4F1C25589919C326088AA6E68B93D5927CD3BF81D5888F0FD4" + "4C5E78FFD57BF8E5AFF5C2D0828EF09D2BD031CCE85182EC34D85D01E094CC76" + "C86C5848E57AC84C6CC94A01A91553D3D7C87FE964B34063AC99DAF282D18263" + "A305D74DDB98CC25CB47199B68F651CF309D6645FADEF2979F954BE69A2EEFF1");
    assertBigInteger("PrimeExponentQ", privateKey.getPrimeExponentQ(), "" + "5A39AB5FD81B37B94DE6931D0E5387C28070A5722D7BD92638B08AD79CE3199A" + "89742F5383489769552781FB4049661E3A7293179C882FF808E13B2795CDBD55" + "A4155026ED7E69BEB5534275F75E77EB0C10EB9F46D11E8C9952C89411ADD61C" + "E2C2A378A209BC5E85E3F94EC50C1DC007797B938F7339142FBD0334C8C02988" + "CCF7E12781A8FF7EFBB4F82BA87D5F61F028B87756F2373A69DF6A352D497A45" + "32F6329ADC26F3F2D0D46B7EEFA8199031B34022C187EF052B6A982013E13ABB");
}
Also used : RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Resource(io.churchkey.Resource) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(io.churchkey.Key) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Test(org.junit.Test)

Example 2 with Resource

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

the class BeginPrivateKeyRsaTest method opensslRsaPublicKey.

@Test
public void opensslRsaPublicKey() throws IOException {
    final Resource resource = Resource.resource(this.getClass().getSimpleName());
    final Key key = Keys.decode(resource.bytes("openssl-rsaprivatekey-3072.pem"));
    final Key publicKey = key.getPublicKey();
    assertNotNull(publicKey);
    assertTrue(publicKey.getKey() instanceof RSAPublicKey);
    assertEquals(Key.Algorithm.RSA, publicKey.getAlgorithm());
    assertEquals(Key.Format.PEM, publicKey.getFormat());
    assertEquals(Key.Type.PUBLIC, publicKey.getType());
}
Also used : RSAPublicKey(java.security.interfaces.RSAPublicKey) Resource(io.churchkey.Resource) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(io.churchkey.Key) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Test(org.junit.Test)

Example 3 with Resource

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

the class BeginPrivateKeyRsaTest method javaRsaPrivateKey.

@Test
public void javaRsaPrivateKey() throws Exception {
    final Resource resources = Resource.resource(this.getClass().getSimpleName());
    final byte[] bytes = resources.bytes("java-rsaprivatekey-3072.pem");
    final Key key = Keys.decode(bytes);
    final RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) key.getKey();
    assertBigInteger("PublicExponent", privateKey.getPublicExponent(), "010001");
    assertBigInteger("Modulus", privateKey.getModulus(), "" + "BC04E5204884EC8514ACC4922BDD2EDC74A065CA53BFF29A41EC42CCEE35BCE7" + "4862EA02AE947A3E4AB9C00116ACDECDD980766138BB8AFA58AF1DD7F87B4227" + "125E69141F7182E49415316A3DD4405A4AA89E4343DABA1B3C5B0A9F7023595F" + "29796771C43E1D24E41FB17BCD6BBDE02B3AF11D2DD70F455E3323F9849586E2" + "A10AE28EB264B783BD333EE7D5807A7C780BC19C220788BDA1D7A442090244E8" + "3CF6E4B77B094B3DF5A3570FCF2B657073C2CAD68D28953768ED468F57E912CA" + "B3ED29C4E0AEE94865569627E4E08409934CE03B2FFA44202815B56461DD8400" + "1E39F3691709CE40BFE54526675C50BE5DC42183B6D042F7C662412703306AAA" + "4DC3FA927C338D4E304D79E0C534F22A0442B02291CD979BA3FAFD0663E1B750" + "F334BE93757AC9440D51B0610EE0E03E58722504A5BFF8F4FE231A9E93765519" + "15A7D3E7F8E941B8F8514CF605763B78C833102BF97C28407023950430C67DB3" + "ADA303AB3E155429EA696B79384E2DCA226E6ACDDD3A934FBEEBFD9E2A26927F");
    assertBigInteger("PrivateExponent", privateKey.getPrivateExponent(), "" + "0F2809DC5F5C2FC0CE98DAC3B9BB7BC293B8365C6801EA299B34D371B7A62753" + "31979FAB95AD2C698716902EC6482B31C6DDBF2D39288D1C7F37A69D394F9E56" + "8DF98458F5EBED944587ABD317A6DB852BCD89EC7C34CE99D174B9577EEFAA8D" + "AC47381A88AA45292B268EE51EFB177451A7CFB5FD72FFAD24D9D48591B58809" + "0ED854C912026274C134B75672F4876B2F362B664DABF3CEED93F78EC73122A2" + "E1FF3912BD5D536E6C35BD97EDA85EE600BEEC20FD820EFD477D111A0F091FD5" + "89EA74F41061B8CE2B9B5C45AAB48657D0B6CBA47459E037D229E1A7D9FD8560" + "A38067845B2C99848B125BCE8A236D96D7EFE29599ACF598928FDB8725558E01" + "3EF8401A33A18C2F94739649BE8BB0E6BB22226E198DCB8616FD0BA303381254" + "14166AA7FC19BBB80C3791F52111DF585F3B250496581A71804935B689B6C4C9" + "82E1DAEF921A16BE1AA5EB3EA5F7CB1B45C2D69CAC8047895B33FB71F0EC0660" + "695053FE882C04C4425564EE4E857CDF33E48A5F1DD9AC9817F2B6DA4D563809");
    assertBigInteger("PrimeP", privateKey.getPrimeP(), "" + "DAD64CCEAE0C7B9E68E7A1DBF01E943D42AFF0821A86E15FAB6BB4D9536537BE" + "2A0CE4DBFD4246E5DD49C051A1DCF0B69A4688E81DF3622322CA2D24C9CF37F5" + "7A51F334ABF496F4C826048F22C3D1E75853DE3CA4BCDB325BAA2F33E958BE04" + "67DDDE5B4AA7114F22EABE9E4605792FCFB2C627D8A84C59C524E8FB568B2DCA" + "E72F092A7E540801B0D29628607D30728C4CFB59A0BE9C7B67ED803B03B742E9" + "16D43112E81C056F0210F54A6E35A8E5DF8BE2C841A1C8320F107E70EF3A3F7D");
    assertBigInteger("PrimeQ", privateKey.getPrimeQ(), "" + "DBF2D135B5872FB13C14A2BDE15D87E39EBEBE0AC87C08332ABCB724AEF14729" + "70B58F69290BACB56C605BBE883FC38C6A0D32C6848835CC89FCDD7211FF96AE" + "F6BF2B592CAA8BE1E15679785C285EB39352B62B515422E770C55CABE9E2C983" + "47E9471F901169DAA7A57E8B404DE3187D0B56EDB1F8ABFEDD2E2AAC09585A1F" + "A14C44BC2B2D88C9F7019A3C05173A75FBA3946EF4886F57C6008D8B91A89524" + "A3462877DC835D8B6A218BF4605F33038713A77CC0EB4B71337A0F0BB042F2AB");
    assertBigInteger("CrtCoefficient", privateKey.getCrtCoefficient(), "" + "279E22AC991DA44F68FD57D5A2AAAC06E88C5AA257E0C5ADDC3C3CC8D01920A7" + "365520B0FE94DF05A5169F4F59BE0EFF4ABFEC1EA27C8374DBECCCD30EBC8527" + "0B4D717C1059317831009FB8586C60B8E62A8ABC0A9F0843C5C988DD32E5656D" + "463AED5B4E523D2A7E889C10FBA634D3CF366140595F2B312B8CA6FD4E5EE2C9" + "E0A68C406181B9B9534A81FFE9E24F97BA5E985B3760C0863A9A4A97860A836D" + "1CCB76FED55B37E7E254744797BE8A754EDA5447B87402515843583A2B9D3403");
    assertBigInteger("PrimeExponentP", privateKey.getPrimeExponentP(), "" + "0BBA20339330280FBD1F6C9514B10ED0999A441134CAB59922DE8ABA7AB599DF" + "1EF1C1F1E8087D34243FA786B85DD6A8726C053A2B20B7C99A3BAB5FA550ED76" + "C22F52112885DAF11328B665D53F1928849B39F595FE68E0B1F8D4BEBB6A7E04" + "4E6C9D55D7124CE328C3DBA32FAD6B691C80400E329612415D47351502F64265" + "F52D981826DCE9F0ED40DBBB1E3097400C34B3E381B1B54107B8BA7E6F1C8B01" + "62AFCC516F0ED15BB9889F1C75FB7A2997692FA5FB9E67D406EAA35BF9F5ED21");
    assertBigInteger("PrimeExponentQ", privateKey.getPrimeExponentQ(), "" + "91FAEA21F49681EFE709672E116ACB6B268C4083D5A684A6B921C18826585B3B" + "C4E3AC0846C6C9DD2BCE147633E5E63AC69475F3CE38BD4440FD4458965B85BE" + "2064A737AB6E9222DC3551AFB1B2D58FE822C8679DB5F2E89B2F529F833F1331" + "FFC373821E5380673047A5E2744E7D805E55ED5F1B75096AC19007A0611F73C9" + "747BB34F147547498C9852AEAD4E4A6DCE1336CC219E800FC889CB682BC7B11D" + "3D04AE8D471D253407BFB62CFEDD907531ECB888135ED7968D6CE099886616BB");
    // Assert we can write the
    final byte[] encoded = key.encode(Key.Format.PEM);
    assertEquals(new String(bytes), new String(encoded));
}
Also used : RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Resource(io.churchkey.Resource) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(io.churchkey.Key) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) Test(org.junit.Test)

Example 4 with Resource

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

the class BeginPrivateKeyTest method opensslEcPrivateKeyParameterSpec.

@Test
public void opensslEcPrivateKeyParameterSpec() throws Exception {
    final Resource resources = Resource.resource(this.getClass().getSimpleName());
    final byte[] bytes = resources.bytes("openssl-ecprivatekey-parameterspec.pem");
    final Key key = Keys.decode(bytes);
    final ECPrivateKey privateKey = (ECPrivateKey) key.getKey();
    assertBigInteger("s", privateKey.getS(), "" + "4CBB21276CF0FDD0FF05BCC89B84A5C54C77B12B453DE3D341AD6F51B34A7E06");
    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 5 with Resource

use of io.churchkey.Resource 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)

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