# JCE 1.2 Problems

Dan Cieslak (cieslakd@ssax.com)
Tue, 20 Jan 1998 12:58:49 -0600

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Gigi Ankeny: "Re: JCE 1.2 Problems"
- Previous message: Josep A Soria: "Security - not working ?"
- Next in thread: Gigi Ankeny: "Re: JCE 1.2 Problems"

    Message-Id: <199801201858.MAA15333@mailgate.chi.ssax.com>

    From: "Dan Cieslak" <cieslakd@ssax.com>

    To: <java-security@web2.javasoft.com>

    Subject: JCE 1.2 Problems

    Date: Tue, 20 Jan 1998 12:58:49 -0600

This is a multi-part message in MIME format.

------=_NextPart_000_0000_01BD25A3.26BF2540
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0001_01BD25A3.26D78F40"

------=_NextPart_001_0001_01BD25A3.26D78F40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I'm having trouble getting simple applications to work

with the new JCE package using JDK 1.2 Beta 2. I have

included the source in this email. The errors that I get occur at

runtime and are complaints that the PBE With MD5 and DES

algorithm either can't be found or wasn't implemented. The DES=20

one complains that SHA-1 could not be found.

Thanks,

Dan Cieslak

------=_NextPart_001_0001_01BD25A3.26D78F40
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">

I'm having trouble = getting simple=20 applications to work

with the new JCE package using JDK 1.2 Beta 2. I = have

included the source in = this=20 email. The errors that I get occur at

runtime and are = complaints that the PBE=20 With MD5 and DES

algorithm either can't be = found or=20 wasn't implemented. The DES

one complains that SHA-1 = could not be=20 found.

Thanks,

Dan = Cieslak

------=_NextPart_001_0001_01BD25A3.26D78F40-- ------=_NextPart_000_0000_01BD25A3.26BF2540 Content-Type: application/octet-stream; name="DESexample.java" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="DESexample.java" /** * Password Based Encryption Example * Dan Cieslak * 01/12/98 * * No copyright information. * * Note this uses the JCE 1.2 Early Access API. It * requires JDK 1.2 Beta. */ import javax.crypto.*; import javax.crypto.spec.*; import javax.crypto.interfaces.*; import com.sun.crypto.provider.*; import java.security.*; /** * Class to demonstrate DES using Java * @author Dan Cieslak * @version 1.0 * */ public class DESexample { public static void main(String args[]) { try { Provider sunJce = new SunJCE(); Security.addProvider(sunJce); KeyGenerator keygen = KeyGenerator.getInstance("DES"); SecretKey desKey = keygen.generateKey(); Cipher desCipher = Cipher.getInstance("DES/ECB"); // Initialize the cipher for encryption desCipher.init(Cipher.ENCRYPT_MODE, desKey); // Our cleartext byte[] cleartext = "This is just an example".getBytes(); // Encrypt the cleartext byte[] ciphertext = desCipher.doFinal(cleartext); // Initialize the same cipher for decryption desCipher.init(Cipher.DECRYPT_MODE, desKey); // Decrypt the ciphertext byte[] cleartext1 = desCipher.doFinal(ciphertext); // Print the strings String clearStr = new String(cleartext); String cipherStr = new String(ciphertext); String clearStr1 = new String(cleartext1); System.out.println(clearStr); System.out.println(cipherStr); System.out.println(clearStr1); } catch (Exception e) { e.printStackTrace(); } } } ------=_NextPart_000_0000_01BD25A3.26BF2540 Content-Type: application/octet-stream; name="PBEexample.java" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="PBEexample.java" /** * Password Based Encryption Example * Dan Cieslak * 01/12/98 * * No copyright information. * * Note this uses the JCE 1.2 Early Access API. It * requires JDK 1.2 Beta. */ import javax.crypto.*; import javax.crypto.spec.*; import javax.crypto.interfaces.*; import com.sun.crypto.provider.*; /** * Class to demonstrate PBE using Java * @author Dan Cieslak * @version 1.0 * */ public class PBEexample { public static void main(String args[]) { PBEKeySpec pbeKeySpec; PBEParameterSpec pbeParamSpec; SecretKeyFactory keyFac; try { // Salt byte[] salt = { (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c, (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99 }; // Iteration count int count = 20; // Create PBE parameter set pbeParamSpec = new PBEParameterSpec(salt, count); // Convert password into SecretKey object, // using a PBE key factory pbeKeySpec = new PBEKeySpec("Do not share this with anybody"); keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec); // Create PBE Cipher Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); // Initialize PBE Cipher with key and parameters pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec); // Our cleartext byte[] cleartext = "This is another example".getBytes(); // Encrypt the cleartext byte[] ciphertext = pbeCipher.doFinal(cleartext); System.out.println(cleartext); System.out.println(ciphertext); } catch (Exception e) { e.printStackTrace(); } } } ------=_NextPart_000_0000_01BD25A3.26BF2540--

- Next message: Gigi Ankeny: "Re: JCE 1.2 Problems"
- Previous message: Josep A Soria: "Security - not working ?"
- Next in thread: Gigi Ankeny: "Re: JCE 1.2 Problems"