Cryptoapplet - a Java Applet that provides cryptography to Javascript

Cryptoapplet is a small (20 kB) and fast, invisible Java Applet that makes it possible to use functions provided by Java Cryptography Architecture in your Javascript code on a web page.

This applet enables Javascript programmers to use the reliable implementation of common cryptographic algorithms provided by Java, which includes password based encryption, public key cryptography and message signing, creation of new RSA key pairs, and hash functions like MD5 and SHA-1.

The applet is being developed and tested with Java 1.5 and Java 1.6 and has no external dependencies. In its default configuration the algorithms used don't require the "unlimited" Sun JCA policy files, which are often missing in default Java installations on Windows computers. New releases are tested with the latest versions of Firefox, Internet Explorer, Opera and Konqeuror.

Javascript API

General functions

Password based encryption

The default algorithm is PBE with SHA-1 and DESede.

Hash functions

Public key cryptography - message signing and encryption

The default algorithm is SHA-1 with RSA and 128-bit AES.

Key based message signatures

The default algorithm is SHA-1 with RSA.

Public key generator

The keys are returned in the hex format expected by setPrivateKey() key. It is possible to protect the private key with a passphrase.

Notes

All data is passed around as Javascript Strings, which are then converted to Java Strings and finally to individual bytes using Java's String.getBytes("UTF-8") method. This means that passwords and passphrases that contain non-ASCII characters might not be portable if your web pages don't use utf-8. It's recommended that you use the utf-8 encoding on all your web pages that use this applet.

The functions report errors by returning either null or false.

Using the applet

The parameters are the default settings and can be omitted.


<applet name="crypto" code="name.styblo.cryptoapplet.CryptoApplet" 
        archive="cryptoapplet.jar" mayscript="true"
        width="0" height="0" >
<param name="debug" value="false" />
<param name="raiseExceptions" value="false" />
<param name="passwordCipher" value="PBEWithSHA1AndDESede" />
<param name="symCipherKeySize" value="128" />
     Required Java installation was not found, this Crypto Applet won't work.
</applet>
    
<script type="text/javascript">
<!--

alert(document.crypto.getVersion());
alert(document.crypto.md5("Hello World"));

// -->
</script>

Working example applications

These example forms do not send out any information and don't use any server backend, all the processing is performed on the client by the applet.

Download

Author and license

This applet is free software available under the terms of the GNU GPL license.

Copyright 2009 Tomas Styblo

tripie@cpan.org