Encipher - try { PBEKeySpec keySpec = new PBEKeySpec(...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.security.*; import java.security.spec.*; i import com.sun.crypto.provider.SunJCE; i import javax.swing.*; import javax.crypto.*; import javax.crypto.spec.*; i public class Encipher { p private static final byte[] salt = { ( byte )0xf5, ( byte )0x33, ( byte )0x01, ( byte )0x2a, ( byte )0xb2, ( byte )0xcc, ( byte )0xe4, ( byte )0x7f }; private int iterationCount = 100; // iteration count String password = "abc123"; public Encipher() { Security.addProvider( new SunJCE() ); String line=null; StringBuffer buffer= new StringBuffer(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while(true) { try { line = in.readLine(); } catch(Exception e){} if(line.equals("")) break; buffer.append(line + "\n"); } String originalText = buffer.toString(); Cipher cipher = null;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: try { PBEKeySpec keySpec = new PBEKeySpec( password.toCharArray() ); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "PBEWithMD5AndDES" ); SecretKey secretKey = keyFactory.generateSecret( keySpec ); PBEParameterSpec parameterSpec = new PBEParameterSpec( salt, iterationCount ); cipher = Cipher.getInstance( "PBEWithMD5AndDES" ); cipher.init( Cipher.ENCRYPT_MODE, secretKey, parameterSpec ); } catch ( Exception e) {} byte outputArray = null; try { outputArray = originalText.getBytes( "ISO-8859-1" ); } catch ( Exception e ) {} CipherOutputStream out = new CipherOutputStream( System.out, cipher ); try { out.write( outputArray ); out.flush(); out.close(); } catch ( Exception e ) {} } public static void main( String args ) { Encipher crypto = new Encipher(); } }...
View Full Document

This note was uploaded on 07/14/2011 for the course COP 4610L taught by Professor Staff during the Spring '09 term at University of Central Florida.

Page1 / 2

Encipher - try { PBEKeySpec keySpec = new PBEKeySpec(...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online