string from CipherOutputStream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eyeofsoul
    New Member
    • Sep 2007
    • 31

    string from CipherOutputStream

    hello..i got problem in my function. this function is for encrypt a string that was pass to this function.
    Code:
    void EncodeData( Cipher aCipher, String plaintext ) throws InvalidKeyException
    {
    	// initialize the Cipher in encrypt mode
    	aCipher.init( Cipher.ENCRYPT_MODE, secretKey );
    
    	byte[] outputArray = null;
    	
    	// produce a byte array from the string, using the platform's
    	// default character set.
                   
    	outputArray = plaintext.getBytes( ); 
            System.out.println("Plaintext :" + plaintext );
            System.out.println( "Before = "+outputArray);
    		
    	FileOutputStream outfile = null;
    	
    	try {
    		outfile = new FileOutputStream( new File( "soul.txt" ) );
    	}
    	catch( IOException e )
    	{ }
    
    	// Create a CipherOutputStream
    	CipherOutputStream out = new CipherOutputStream( outfile, aCipher );
          
    	try {
    		out.write( outputArray );
                    out.flush( );
    		out.close( );
                    System.out.println("CipherText: ");
    	}
    	catch( IOException e )
    	{
    		e.printStackTrace( );
    	}	
    	
    	// erase the unencrypted data
    	java.util.Arrays.fill( outputArray, (byte)0 );
    }
    instead of me writing the encrypted plaintext, i want to display the cipher text. i couldn't find the way. things that i try to displayed are not like in the soul.txt.
Working...