- From: Ari Kermaier <arik@phaos.com>
- Date: Mon, 15 Dec 2003 11:22:39 -0500
- To: "Kim Yuna" <existion@postech.ac.kr>, <xml-encryption@w3.org>
- Message-ID: <002601c3c327$a8bc4f00$6501a8c0@arilaptop>
I haven't tested this with Bouncy Castle, but you might try instantiating a KeyFactory for "DiffieHellman", instead of "DH". ::Ari ----- Original Message ----- From: Kim Yuna To: xml-encryption@w3.org Sent: Sunday, December 14, 2003 11:20 AM Subject: how to read PKCS#8 file Dear all, I tried to test Diffie-Hellman algorithm using 01-phaos-xmlenc-3. First, i need to read dh-priv-key.der, but i cannot. My program is very simple like this. ------------------------------------------- private static byte[] getRawKey(String strFile) throws Exception { File keyfile = new File(strFile); DataInputStream in = new DataInputStream(new FileInputStream(keyfile)); byte[] rawkey = new byte[(int)keyfile.length()]; in.readFully(rawkey); in.close(); return rawkey; } public static void main(String[] args) throws Exception { Security.addProvider(new BouncyCastleProvider()); byte[] buffer = getRawKey("dh-priv-key.der"); KeyFactory kf = KeyFactory.getInstance("DH"); PKCS8EncodedKeySpec keysp = new PKCS8EncodedKeySpec (buffer); System.out.println(keysp.toString()); try{ PrivateKey pk = kf.generatePrivate(keysp); } catch(Exception e) { e.printStackTrace(); } } --------------------------------- i get an error, java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: algorithm identifier in key not recognised at org.bouncycastle.jce.provider.JDKKeyFactory$DH.engineGeneratePrivate(JDKKeyFactory.java:331) at java.security.KeyFactory.generatePrivate(KeyFactory.java:197) at Test.CertificateTest.main(CertificateTest.java:60) Please, help me. Thank you in advance. ------------------------------------------- Yuna Kim CSE, HPC lab in POSTECH phone : +82-054-279-2915 cellp : 016-324-7963 -------------------------------------------
Received on Monday, 15 December 2003 11:23:27 UTC