Decipher - PBEParameterSpec parameterSpec = new...

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.*; import com.sun.crypto.provider.SunJCE; import javax.swing.*; import javax.crypto.*; import javax.crypto.spec.*; i public class Decipher { 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 Decipher() { Security.addProvider( new SunJCE() ); Vector fileBytes = new Vector(); Cipher cipher = null; try { PBEKeySpec keySpec = new PBEKeySpec( password.toCharArray() ); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "PBEWithMD5AndDES" ); SecretKey secretKey = keyFactory.generateSecret( keySpec );
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: PBEParameterSpec parameterSpec = new PBEParameterSpec( salt, iterationCount ); cipher = Cipher.getInstance( "PBEWithMD5AndDES" ); cipher.init( Cipher.DECRYPT_MODE, secretKey, parameterSpec ); } catch ( Exception e) {} try{ CipherInputStream in = new CipherInputStream( System.in, cipher ); byte contents = ( byte ) in.read(); while ( contents != -1 ) { fileBytes.add( new Byte( contents ) ); contents = ( byte ) in.read(); } in.close(); } catch ( Exception e) {} byte decryptedText = new byte[ fileBytes.size() ]; for ( int i = 0; i < fileBytes.size(); i++ ) decryptedText[ i ] = ( ( Byte )fileBytes.elementAt( i ) ).byteValue(); System.out.println( new String( decryptedText ) ); } public static void main( String args ) { Decipher crypto = new Decipher(); } }...
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

Decipher - PBEParameterSpec parameterSpec = new...

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