====== How to sign an applet ====== ^versions^ALL^ |contributors|[[user:irag]]| |started on|2008-09-20 09:53| By default Java applications are considered safe to run, or in Java speak //trusted//, since they are executed explicitly by users on their own computers. Applets by comparison are considered //untrusted// since they are initiated automatically in the browser. This restriction prevents applets from doing certain things, such as loading content from a different domain than the one hosting the applet. The error generated will look something like://java.security.AccessControlException: access denied (java.net.SocketPermission some URL here connect,resolve).// To override this restriction, you can can //sign// the applet. There are a couple different approaches to signing an applet, but they each involve connecting a certificate to your jar file. Certificates are digital signatures that incorporate a public key with some identity. There are companies (Certificate Authorities) that sell certificates for hundreds of dollars, but it is also possible to create a self-sign certificate for free, which is the approach shown below. The //select_image// sketch below the instructions attempts to load an image from your computer using a standard file browser. When run as an applet, it **needs** to be signed. ===== Instructions ===== Assume you have a sketch named **loadImage.pde** - Export your sketch as an applet, creating loadImage.jar. (Please note that if core.jar was also created, you have "Use multiple .jar files when exporting applets" checked in Processing's preferences window. I recommend unchecking this setting and re-exporting the sketch. Otherwise you'll need to sign both .jar files. - Open a terminal program and navigate to the applet directory where loadImage.jar is located. - type ''keytool -genkey -keystore pKeyStore -alias p5geek'' - type ''keytool -selfcert -keystore pKeyStore -alias p5geek'' - type ''jarsigner -keystore pKeyStore //loadImage//.jar p5geek'' - Upload your applet * obviously replace //loadImage// with the real name of your .jar file ===== Source code ===== /** How to sign an applet taken from http://processinghacks.com/hacks:signapplet @author Ira Greenberg */ /* To run this sketch as an applet, it MUST be signed */ void setup(){ size(400, 400); PImage img; String imgName = selectInput(); img = requestImage(imgName); image(img, 0, 0); } ===== Related Links ===== Please list any links you think are essential reading related to this hack: [[http://processing.org]]