Date: Mon, 8 Jun 1998 12:00:13 -0700 (PDT)
From: Jan Luehe <Jan.Luehe@Eng>
Subject: Re: Your Message Sent on Mon, 8 Jun 1998 09:29:56 -0400
To: java-security@web3.javasoft.com, omar@yacht.ee.fit.edu
Hi:
The "DSA" algorithm is irreversible. Therefore, you cannot
use it for encryption/decryption.
Therefore, your call "Cipher.getInstance ("DSA")" must fail.
You can use RSA for asymmetric encryption, though. If you
had a provider that supplied RSA encryption, and you replaced
all "getInstance" calls requesting "DSA" with "RSA", your
program should work.
Due to licensing restrictions, the SunJCE provider does not
supply an implementation of RSA. If you have access to the
Bsafe toolkit from RSA Data Security (RSA DSI), you could write your
own provider of RSA (by writing Java wrapper code around the
Bsafe native implementation).
Please note that the Jsafe toolkit from RSA DSI supplies
a Java implementation of RSA. Jsafe 2.0, which will be released
sometime this summer/fall, will be compatible with JCE 1.2,
i.e., you will be able to attach their (RSA) provider to JCE 1.2.
Thanks,
Jan
> I am trying to practice doing encryption and decryption using both the DES and
> the public and private keys too. I used the DES way according to the the Java
> Cryptography Extension 1.2 API Specification & Reference (Last Modified : 12
Feb -1998). I did not find any thing helpful in these notes about asymmetric
> cryptography and I wish to have a sample code showing me that because I did
typed some code as shown below and I go the message shown below too. Your reply
to my question is appreciated and thank you.
> import java.io.*;
> import java.util.*;
> import java.math.BigInteger;
> import java.security.*;
> import java.security.spec.*;
> import javax.crypto.*;
> import javax.crypto.spec.*;
> import javax.crypto.interfaces.*;
> import com.sun.crypto.provider.SunJCE;
>
> public class Sample2 {
> public static void main (String args[]) {
> try {
> // Provider sunJce = new com.sun.crypto.provider.SunJCE();
> SunJCE jce = new SunJCE();
> Security.addProvider(jce);
> // Security.addProvider(sunJce);
> KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
> keyGen.initialize(512, new SecureRandom());
> KeyPair pair = keyGen.generateKeyPair();
> PrivateKey priv = pair.getPrivate();
> PublicKey pub = pair.getPublic();
>
> Cipher cipher1 , cipher2;
> cipher1 = Cipher.getInstance ("DSA");
> cipher2 = Cipher.getInstance ("DSA");
>
> // Initialize the cipher for encryption
>
> cipher1.init(Cipher.ENCRYPT_MODE, pub);
> cipher2.init(Cipher.DECRYPT_MODE, priv);
>
> FileInputStream fis = new FileInputStream("a.txt");
> FileOutputStream fos = new FileOutputStream("b.txt");
> CipherInputStream cis1 = new CipherInputStream(fis, cipher1);
>
> byte[] b = new byte[256];
> int i = cis1.read(b);
> while (i != -1) {
> fos.write(b, 0, i);
> i = cis1.read(b);
>
> }
> fis.close();
> fos.close();
> cis1.close();
>
> FileInputStream fis1 = new FileInputStream("b.txt");
> FileOutputStream fos1 = new FileOutputStream("c.txt");
> CipherInputStream cis2 = new CipherInputStream(fis1, cipher2);
> byte[] b1 = new byte[256];
> int j = cis2.read(b1);
> while (j != -1) {
>
> fos1.write(b1, 0, j);
> j = cis2.read(b1);
> }
> fis1.close();
> fos1.close();
> cis2.close();
>
> } catch (Exception e) {
> System.err.println("Error: " + e);
> }
> }
>
> Error: java.security.NoSuchAlgorithmException: algorithm DSA not available.
>
>