This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
javax.crypto
- From: Marco Trudel <mtrudel at gmx dot ch>
- To: GCJ <java at gcc dot gnu dot org>
- Date: Wed, 20 Sep 2006 20:33:01 +0200
- Subject: javax.crypto
Hello list
I use a --disable-shared GCJ, built two days ago (revision 117030)...
What's the state of javax.crypto? Gnu classpath states that they
implemented it mostly. But when running a compiled test app (attached),
I get:
WARNING: Error loading security provider gnu.javax.crypto.jce.GnuCrypto:
java.lang.ClassNotFoundException: gnu.javax.crypto.jce.GnuCrypto
WARNING: Error loading security provider gnu.javax.crypto.jce.GnuSasl:
java.lang.ClassNotFoundException: gnu.javax.crypto.jce.GnuSasl
WARNING: Error loading security provider
gnu.javax.net.ssl.provider.Jessie: java.lang.ClassNotFoundException:
gnu.javax.net.ssl.provider.Jessie
WARNING: Error loading security provider
gnu.javax.security.auth.callback.GnuCallbacks:
java.lang.ClassNotFoundException:
gnu.javax.security.auth.callback.GnuCallbacks
Exception in thread "main" java.security.NoSuchAlgorithmException:
PBEWithMD5AndDES
at javax.crypto.SecretKeyFactory.getInstance(bin)
at CryptionUtilities.crypt(bin)
at CryptionUtilities.main(bin)
Do I miss some requirements? I didn't find anything on the net...
thanks
Marco
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
public class CryptionUtilities
{
public static void main(String[] args) throws Exception
{
byte[] encrypted = crypt("hello world!".getBytes(), "password", Cipher.ENCRYPT_MODE);
System.out.println("encrypted: [" + new String(encrypted) + "[ " + encrypted.length);
byte[] decrypted = crypt(encrypted, "password", Cipher.DECRYPT_MODE);
System.out.println("decrypted: ]" + new String(decrypted) + "[ " + decrypted.length);
}
private static byte[] crypt(byte[] inBytes, String password, int mode) throws Exception
{
// 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
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
// convert the password into a SecretKey object, using a PBE key factory.
PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray());
SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); // #NI#
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
// Create PBE Cipher
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); // #NI#
// Initialize PBE Cipher with key and parameters
pbeCipher.init(mode, pbeKey, pbeParamSpec);
// do the Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE
byte[] done = pbeCipher.doFinal(inBytes);
return done;
}
}