Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > BOOK: Beginning Cryptography with Java
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Cryptography with Java
This is the forum to discuss the Wrox book Beginning Cryptography with Java by David Hook; ISBN: 9780764596339
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Cryptography with Java section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 23rd, 2012, 12:04 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with the examples

Hello ,
i have a problem in the source code of the examples of the book :
the book example :
Code:
package chapter1;

import javax.crypto.*;
import javax.crypto.spec.*;

public class SimplePolicyTest
{
    public static void main(String[] args) throws Exception
    {
        byte[]     data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };

        // create a 64 bit secret key from raw bytes
        SecretKey key64 = new SecretKeySpec(
                   new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
                   "Blowfish");

        // create a cipher and attempt to encrypt the data block with our key
        Cipher     c = Cipher.getInstance("Blowfish/ECB/NoPadding");

        c.init(Cipher.ENCRYPT_MODE, key64);
        c.doFinal(data);
        System.out.println("64 bit test: passed");

        // create a 192 bit secret key from raw bytes
        SecretKey key192 = new SecretKeySpec(
                    new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                                 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
                                 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
                    "Blowfish");

        // now try encrypting with the larger key
        c.init(Cipher.ENCRYPT_MODE, key192);
        c.doFinal(data);

        System.out.println("192 bit test: passed");

        System.out.println("Tests completed");
    }
}
when i come to compile it , it give me an error that there is no exceptions .
so i add all the exceptions and made try .... catch ..... etc .
Is there a solution for that ? or even an shortcut ?
or can i modify the compiler to ignore these stuff ?

Thanks in advance .
Reply With Quote
  #2 (permalink)  
Old February 23rd, 2012, 03:38 PM
dgh dgh is offline
Wrox Author
Points: 843, Level: 11
Points: 843, Level: 11 Points: 843, Level: 11 Points: 843, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 203
Thanks: 0
Thanked 19 Times in 19 Posts
Default

Can you tell me what the actual error is? What JVM are you using?

Thanks,

David
Reply With Quote
  #3 (permalink)  
Old February 23rd, 2012, 03:43 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your replay ...
Sorry it was my fault that i forgot to write "throws Exception"

Thanks for your replay.
Reply With Quote
  #4 (permalink)  
Old February 23rd, 2012, 07:05 PM
dgh dgh is offline
Wrox Author
Points: 843, Level: 11
Points: 843, Level: 11 Points: 843, Level: 11 Points: 843, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 203
Thanks: 0
Thanked 19 Times in 19 Posts
Default

But what is the exception?

Regards,

David
Reply With Quote
  #5 (permalink)  
Old February 24th, 2012, 03:10 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception java.security.NoSuchAlgorithmException; must be caught or declared to be thrown
	at test.main(test.java:16)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
Reply With Quote
  #6 (permalink)  
Old February 26th, 2012, 06:10 AM
dgh dgh is offline
Wrox Author
Points: 843, Level: 11
Points: 843, Level: 11 Points: 843, Level: 11 Points: 843, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 203
Thanks: 0
Thanked 19 Times in 19 Posts
Default

You've left out "throws Exception" from the public static void main declaration.

Regards,

David
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem loading examples.bat for Pubs database tscherb BOOK: Professional Visual Basic 2010 and .NET 4 3 April 21st, 2011 05:08 PM
Problem running the examples alatriste BOOK: Professional Microsoft Robotics Studio ISBN: 978-0-470-14107-6 1 September 19th, 2009 06:47 PM
[resolved] Trinidad & Tomcat Problem with examples pouet Apache Tomcat 1 May 11th, 2007 09:27 AM
problem with first test examples _l_ ASP.NET 1.0 and 1.1 Basics 1 July 5th, 2006 09:42 PM
Problem with examples in Access 2002 VBA tcarnahan BOOK: Beginning Access VBA 0 January 26th, 2004 07:14 PM



All times are GMT -4. The time now is 04:10 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.