Professional Documents
Culture Documents
Tutorial 4 Cryptography Algorithms in JAVA: Objectives
Tutorial 4 Cryptography Algorithms in JAVA: Objectives
Tutorial 4 Cryptography Algorithms in JAVA: Objectives
Objectives
Exercises
a) Application
java program
b) Applet
First, you should write a HTML file (e.g. program.html)
to invoke this java apple, then you can use appletviewer
program.html or use IE, Netscape to open this HTML file.
Examples
import java.io.*;
public class HelloKitty {
public static void main(String args[]) {
System.out.println(“HelloKitty”);
}
}
import java.applet.*;
import java.awt.*;
<HTML>
<HEAD>
<TITLE>A HTML to test applet</TITLE>
</HEAD>
<BODY>
<applet code="HelloKitty2.class" Width="80" Height="100">
</applet>
</BODY>
</HTML>
Developer.com: http://java.developer.com
The Java Security API is a set of packages that are used for
writing secure programs in Java. In particular, the classes
and interfaces in the following packages are part of the
Security API:
java.security.Key
java.security.PrivateKey Use to encrypt and sign
java.security.PublicKey messages
javax.crypto.SecretKey
java.crypto.Cipher Cipher
java.security.MessageDigest Message digest function
java.security.Signature Digital signature
java.security.cert.Certificate Authentication
java.security.KeyFactory
Symmetric Keys and
javax.crypto.KeyAgreement
Asymmetric Keys
javax.crypto.KeyGenerator
management
javax.crypto.SecretKeyFactory
Secure random number
java.security.SecureRandom
generator
Javax.crypto.Mac Message Authentication Code
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
if (args.length < 1) {
System.out.println("Usage: java EncryptFile <file name>");
System.exit(-1);
}
try {
File desFile = new File("encrypt.des");
FileInputStream fis;
FileOutputStream fos;
CipherInputStream cis;
} catch(IOException err) {
System.out.println("Cannot open file!");
System.exit(-1);
}
cis = new CipherInputStream(fis, encrypt);
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
FileInputStream fis;
FileOutputStream fos;
CipherInputStream cis;
import java.net.*;
import java.io.*;
if (args.length!=1) {
System.out.println("Usage: UrlRetriever <URL>");
System.exit(-1);
}
try {
URL url=new URL(args[0]);
BufferedInputStream buffer=new
BufferedInputStream(url.openStream());
5 Exercises