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 .
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 ?
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)