Home Page Javascript Download Core Servlets & Java Server Java Cryptography Java in 60 Min A Day Javascript Tutorial About Us Contact Us
Site Search
Free Javascript Lessons
Newest Java Articles
Checkbox Changer
Check Entry
Check All
Block Key Press
Basic Validation
Auto Email Link
JavaScript Forms: Agree Before Entry
Auto Tab
JavaScript Calendars: Time Entered - Day Highlighted
JavaScript Calendars: Days Left
Related SE Keywords
Java virtual machine
Java Applet
Javascript Lesson
Javascript Tutorial
Java Programming
Java Games
Java Xml
Java String
Cryptography Extensions
Free Web Master Tools
 
JavascriptDownload.net > Free Javascript Lessons > Java Cryptography Extensions > Chapter 1 / 1 - Understanding Java's Cryptographic Architecture

Cryptography has its roots in very complex (and often theoretical) mathematics. As a result, computers and cryptography complement each other well. Today's advanced cryptographic operations involve mind-boggling amounts of mathematical calculations, and computers perform these calculations exponentially faster than a human can perform them by hand. The Java language includes a well-defined architecture that allows you to include cryptographic services in your designs without fully comprehending the mathe­matical proofs or calculations behind the algorithms. However, this does not mean that it is not important to understand the algorithms (i.e., the cryptographic tools) at your disposal. As an analogy, a screwdriver is a wonderful tool for driving a wood screw into a piece of wood; however, that same screwdriver would not be effective if the object being driven was a finishing nail.

Performing cryptographic operations with Java does not involve hundreds of lines of code or require a Ph.D. in mathematics from MIT. Perhaps the most visible aspect of cryptography is encryption, which can be accomplished in Java using as little as seven lines of code, not counting proper exception handling. Here is a brief example demon­strating a simple encryption operation. Don't worry about comprehending every aspect of the program just yet—we have the whole book to explore Java's cryptographic capabilities!

 

NOTE: Please review the preface for code style information and download instructions.

 

Example 1.1 Sample Code Location: com.mkp.jce.chapl.SmallExample

 

try

{


 

//Lookup a key generator for the DES cipher KeyGenerator kg = KeyGenerator.getInstance("DES");

 

//Generate a secret key that can be used by the DES cipher SecretKey key = kg.generateKeyO;

SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "DES");

 

//Lookup an instance of a DES cipher Cipher cipher = Cipher.getlnstance("DES");

 

//Initialize the cipher using the secret key cipher.init(Cipher.ENCRYPT_MODE, keySpec);

 

//Encrypt our message

String plainText = "This is a secret message";

byte[] cipherText = cipher.doFinal(plainText.getBytesO);

 

System.out.println("Resulting Cipher Text:n");

for(int i=0;i<cipherText.length;i++)

{

System.out.print(cipherText[i] + " ");

}

System.out.println("");

 

} catch (Exception e) {

e.printStackTraceO;

}

Add Comment
 
homepage   |  about us  |  contact us
Powered By teknonova.com Sunucu Kiralama