Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Problem running modified snippet standalone
Problem running modified snippet standalone [message #436999] Thu, 27 May 2004 19:53
Rohit Singh is currently offline Rohit SinghFriend
Messages: 1
Registered: July 2009
Junior Member
I took Tray snippet from swt page and added code to initialize cipher and
I always get following

Exception in thread "main" java.lang.InternalError: internal error: SHA-1
not av
ailable.
at javax.crypto.f.e(Unknown Source)
at javax.crypto.f.f(Unknown Source)
at javax.crypto.g.run(Unknown Source)
at java.security.AccessController.doPrivileged1(Native Method)
at
java.security.AccessController.doPrivileged(AccessController .java:350
)
at javax.crypto.f.<clinit>(Unknown Source)
at javax.crypto.SecretKeyFactory.getInstance(Unknown Source)
at swt.TrayMain2.go(TrayMain2.java:131)
at swt.TrayMain2.main(TrayMain2.java:56)


Here is the jdk I am using
C:\Work\eclipse\workspace\Test\build>java -version
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1)
Classic VM (build 1.4.1, J2RE 1.4.1 IBM Windows 32 build cn1411-20040301a
(JIT e
nabled: jitc))


and here is the modified code

/*
* Copyright (c) 2000, 2003 IBM Corp. All rights reserved. This file is
made
* available under the terms of the Common Public License v1.0 which
accompanies
* this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/

/*
* Tray example snippet: place an icon with a popup menu on the system tray
*
* For a list of all SWT example snippets see
*
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
*/

package swt;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.CodeSource;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.util.Enumeration;

import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;

public class TrayMain2 {

public static void main(String[] args) {
TrayMain2 tr2 = new TrayMain2();
tr2.go();
}

private void go() {

URL codebase = null;
try {
// Get permissions for a URL
// codebase = new URL("http://java.sun.com/");

// Get permissions for a directory
codebase = new File("c:\\Work\\SWT\\").toURL();
// codebase = new File("c:\\users\\almanac\\").toURL();
// codebase = new File(System.getProperty("user.home")).toURL();
} catch (MalformedURLException e) {
}

// Construct a code source with the code base
CodeSource cs = new CodeSource(codebase, null);

// Get all granted permissions
PermissionCollection pcoll = Policy.getPolicy().getPermissions(cs);

// View each permission in the permission collection
Enumeration enum = pcoll.elements();
for (; enum.hasMoreElements(); ) {
Permission p = (Permission)enum.nextElement();
System.out.println(p);
}

Display display = new Display();
Shell shell = new Shell(display);
Image image = new Image(display, 16, 16);
final Tray tray = display.getSystemTray();
final TrayItem item = new TrayItem(tray, SWT.NONE);

printPermission(this.getClass());
printPermission(display.getClass());
printPermission(shell.getClass());
printPermission(image.getClass());
printPermission(tray.getClass());
printPermission(item.getClass());

Cipher ecipher;

Cipher dcipher; String passPhrase = "this sucks";
// 8-bytes Salt
byte[] salt = { (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte)
0x32, (byte) 0x56, (byte) 0x34, (byte) 0xE3, (byte) 0x03};

// Iteration count
int iterationCount = 19;

try {

byte[] keyArray = new byte[24];

// System.arraycopy(passPhrase.getBytes(), 0, keyArray, 0,
passPhrase.getBytes().length > 24 ? 24 : passPhrase.getBytes().length);

KeySpec keySpec = new DESedeKeySpec(keyArray);

// KeySpec keySpec2 = new PBEKeySpec(passPhrase.toCharArray(),
salt, iterationCount);
KeySpec keySpec2 = new PBEKeySpec(passPhrase.toCharArray());

KeySpec ks = new SecretKeySpec(passPhrase.getBytes(), "AES");
// PBEWithMD2AndDES
// PBEWithMD2AndDESede
// PBEWithMD2AndRC2
// PBEWithMD2AndTripleDES
// PBEWithMD5AndDES
// PBEWithMD5AndDESede
// PBEWithMD5AndRC2
// PBEWithMD5AndTripleDES
//PBEWithMD2AndDESede

// SecretKey key =
SecretKeyFactory.getInstance("DESede").generateSecret(keySpec);
==> line 131 SecretKey key =
SecretKeyFactory.getInstance("PBEWithMD5AndTripleDES").generateSecret(ks);

// SecretKey key2 =
SecretKeyFactory.getInstance("PBEWithMD5AndTripleDES").generateSecret(keySpec2);
SecretKey key2 =
SecretKeyFactory.getInstance("PBEWithMD5AndTripleDES").generateSecret(ks);

ecipher = Cipher.getInstance("PBEWithMD5AndTripleDES");
dcipher = Cipher.getInstance("PBEWithMD5AndTripleDES");
// ecipher = Cipher.getInstance("PBEWithMD5AndTripleDES");
// dcipher = Cipher.getInstance("PBEWithMD5AndTripleDES");
// ecipher = Cipher.getInstance("Blowfish");
// dcipher = Cipher.getInstance("Blowfish");
// ecipher =
Cipher.getInstance(key2.getAlgorithm());
// dcipher =
Cipher.getInstance(key2.getAlgorithm());

// Prepare the parameters to the cipthers
AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt,
iterationCount);

ecipher.init(Cipher.ENCRYPT_MODE, key2, paramSpec);
dcipher.init(Cipher.DECRYPT_MODE, key2, paramSpec);

} catch (InvalidAlgorithmParameterException e) {
System.err.println("EXCEPTION:
InvalidAlgorithmParameterException");
e.printStackTrace();
} catch (InvalidKeySpecException e) {
System.err.println("EXCEPTION: InvalidKeySpecException");
e.printStackTrace();
} catch (NoSuchPaddingException e) {
System.err.println("EXCEPTION: NoSuchPaddingException");
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
System.err.println("EXCEPTION: NoSuchAlgorithmException");
e.printStackTrace();
} catch (InvalidKeyException e) {
System.err.println("EXCEPTION: InvalidKeyException");
e.printStackTrace();
}

item.setToolTipText("SWT TrayItem");
item.addListener(SWT.Show, new Listener() {

public void handleEvent(Event event) {
System.out.println("show");
}
});
item.addListener(SWT.Hide, new Listener() {

public void handleEvent(Event event) {
System.out.println("hide");
}
});
item.addListener(SWT.Selection, new Listener() {

public void handleEvent(Event event) {
System.out.println("selection");
}
});
item.addListener(SWT.DefaultSelection, new Listener() {

public void handleEvent(Event event) {
System.out.println("default selection");
}
});
final Menu menu = new Menu(shell, SWT.POP_UP);
for (int i = 0; i < 8; i++) {
MenuItem mi = new MenuItem(menu, SWT.PUSH);
mi.setText("Item" + i);
}
item.addListener(SWT.MenuDetect, new Listener() {

public void handleEvent(Event event) {
menu.setVisible(true);
}
});
item.setImage(image);
shell.setBounds(50, 50, 300, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
image.dispose();
display.dispose();
}

/**
*
*/
private void printPermission(Class c) {
// Get the protection domain for the class
ProtectionDomain domain = c.getProtectionDomain();

// With the protection domain, get all the permissions from the
Policy object
PermissionCollection pcoll =
Policy.getPolicy().getPermissions(domain);

// View each permission in the permission collection
Enumeration enum = pcoll.elements();
System.out.println("\n\n\n");
for (; enum.hasMoreElements(); ) {
Permission p = (Permission)enum.nextElement();
System.out.println(p);
}
}
}


If I move every thing to jre/lib/ext it works
it works from inside eclipse M9 with same jdk

It does not work stand alone.

I am stumped please advise.
Previous Topic:Default RCP app look with M9 differs between Linux and Windows !
Next Topic:TableViewer and adding rows
Goto Forum:
  


Current Time: Tue Apr 23 14:09:26 GMT 2024

Powered by FUDForum. Page generated in 0.04938 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top