I have the following simple program, which is taken as a line from Amazon EC2 sample program (doing some SSL).
//=================================
import javax.crypto.Mac;

public class MacTest {
public static void main(String[] args) throws Exception {
Mac mac = Mac.getInstance("HmacSHA1");
}
}
//=================================

I run it in MacOSX 10.6 command line, and it was fine. But when I run it in Eclipse, I have the following exception:

Exception in thread "main" java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available
at javax.crypto.Mac.getInstance(DashoA13*..)
at MacTest.main(MacTest.java:6)

What is the reason of this? Is it because of permissions? Thanks.

I run it again with -verbose:class option on to see which classes are loaded. The jce.jar file and others loaded in the two environments are exactly the same: (symlinks point to the same jar files)

COMMAND LINE:
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
...
[Opened
/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar]

ECLIPSE:
[Opened
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar]
...
[Opened
/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar]
[Opened
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/ui.jar]
[Opened
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jsse.jar]
[Opened
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jce.jar]
[Opened
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/charsets.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar]
[Opened
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar]
Collapse All Comments
Expand All Comments