Dobry den, zda se, ze podpora algoritmu zalezi na JCE providerovi, ktery mate k dispozici. Zde je odstavec z dokumentace pro "keytool":
Supported Algorithms and Key Sizes keytool allows users to specify any key pair generation and signature algorithm supplied by any of the registered cryptographic service providers. That is, the keyalg and sigalg options for various commands must be supported by a provider implementation. The default key pair generation algorithm is "DSA". The signature algorithm is derived from the algorithm of the underlying private key: If the underlying private key is of type "DSA", the default signature algorithm is "SHA1withDSA", and if the underlying private key is of type "RSA", the default signature algorithm is "MD5withRSA". When generating a DSA key pair, the key size must be in the range from 512 to 1024 bits, and must be a multiple of 64. The default key size for any algorithm is 1024 bits. ---------- Standardne tedy mate moznost pouzit RSA anebo DSA. Pro dalsi algoritmy by asi bylo treba pouzit bohatsi implementaci JCE (asi BouncyCastle). Vice zde: http://www.bouncycastle.org/wiki/display/JA1/X.509+Public+Key+Certificate+and+Certification+Request+Generation mp. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lukas Zapletal Sent: Tuesday, November 28, 2006 15:14 PM To: Java Subject: Spam:Re: Applet pro práci s certifikáty Jeste jednou diky, funguje to. Zajimave je, ze heslo klice je stejne jako heslo celeho certifikatu, dokumentace tvrdi, ze to nemusi byt pravidlem, me se ale pri exportu z Mozilly na druhe heslo program neptal... Sestavit podepisovaci kod jiz bylo snadne. Co me vsak trosku zarazilo -- na zaklade typu klice musim rozhodnout o algoritmu. Java nabizi md5, sha s dsa a rsa sifrovanim, ale co kdyz bude mit certifikat klic pro jiny algoritmus? Stava se to, nebo jsou DSA a RSA (u nasich autorit) tak vyuzivane, ze se to prakticky nemuze stat? byte[] data = "Toto je test".getBytes(); Signature dsa = Signature.getInstance("SHA1withRSA"); dsa.initSign(privateKey); dsa.update(data); byte[] sig = dsa.sign(); System.out.println("signature:" + dsa); System.out.println("signature data:" + sig); dsa.initVerify(chain[0]); dsa.update(data); boolean verifies = dsa.verify(sig); System.out.println("signature verifies: " + verifies); Jen pro informaci: potrebuji udelat applet, ktery se pokusi certifikat najit v prohlizeci (JRE 5.0 tohle umi s IE standardne, s Firefoxem pres nejaky JSS/NSS plugin), pokud jej nenajde, tak bude pozadovat certifikat z disku. Applet bude pak podepisovat odesilana data ve formularich, podobne, jako to ma treba eBanka. Snad to nejak pujde udelat, momentalne resim problem, jak se dostat do globalniho javovskeho keystore (toho ktery je dostupny v Ovladacich panelech -- v ControlPanelu na Linuxu). Poslednim (asi nejtezsim krokem) bude dostat ty certifikaty z prohlizece -- u MSIE by to melo IMHO byt tak, ze se automaticky objevi v Java certifikatech. Diky za tu poznamku o bezpecnosti, jestli to ma byt nebo nema byt bezpecne nerozhoduji (nastesti) ja, mam to jen naprogramovat :-) 2006/11/28, Martin Kuba <[EMAIL PROTECTED]>: > Lukas Zapletal wrote: > > Diky za info. Nedari se mi vsak importovat certifikat ve formatu > > PKCS#12, nevite jak na to? Hledam v dokumentaci, ale ackoliv se JCE > > ve verzi 1.5 chlubi tim, ze by to mela podporovat, tak to nemohu najit. > > Vim. Ale v PKCS12 souboru nebyva jen certifikat, ale i tajny klic a > cely retezec certifikatu zacinajici korenovou certifikacni autoritou. > Nactete ho takhle: > > static KeyStore nactiKeyStore(String ksfile,String password) throws > KeyStoreException,CertificateException,NoSuchAlgorithmException,IOExce > ption > { > //urci typ keystore > String kstype = null; > if(ksfile.endsWith(".ks")) { kstype = "JKS"; } > if(ksfile.endsWith(".p12")) { kstype = "PKCS12"; } > if(kstype==null) { > System.err.println("keystore file name "+ksfile+" must end > with .ks (JKS) or .p12 (PKCS12)"); > System.exit(1); > } > > //nacti keystore > KeyStore store = KeyStore.getInstance(kstype); > store.load(new FileInputStream(ksfile), password.toCharArray()); > return store; > } > ... > > KeyStore ks1 = nactiKeyStore("soubor.p12","heslosouboru"); > String alias = null; > for(Enumeration e = ks1.aliases();e.hasMoreElements();) { > String a = (String)e.nextElement(); > if (ks1.isKeyEntry(a)) { alias = a; } } > System.out.println("alias tajneho klice: "+alias); PrivateKey > privateKey = (PrivateKey) > ks1.getKey(alias,"hesloklice".toCharArray()); > System.out.println("PrivateKey:"+privateKey.getAlgorithm()+"/"+private > Key.getFormat()); Certificate[] chain = > ks1.getCertificateChain(alias); > System.out.println("X509: "+((X509Certificate) > chain[0]).getSubjectX500Principal().getName()); > > > Makub > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Supercomputing Center Brno Martin Kuba > Institute of Computer Science email: [EMAIL PROTECTED] > Masaryk University http://www.ics.muni.cz/~makub/ > Botanicka 68a, 60200 Brno, CZ mobil: +420-603-533775 > -------------------------------------------------------------- > > -- Lukas Zapletal http://lukas.zapletalovi.com
