Results 1 to 6 of 6
- 02-22-2012, 04:36 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 18
- Rep Power
- 0
Uncompilable source code - Erroneous sym type: Utils.createFixedRandom?
Hello there. I got this code for El Gamal algorithm but it's not working. The error is as stated in title.
Thanks in advance :DJava Code:package crypto; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; import java.security.Key; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; import java.util.*; import javax.crypto.Cipher; import javax.crypto.spec.DHParameterSpec; /** * El Gamal example with random key generation. */ public class Crypto { public static void main(String[] args) throws Exception { byte[] input = new byte[] { (byte)0xbe, (byte)0xef }; Cipher cipher = Cipher.getInstance( "ElGamal/None/NoPadding", "BC"); SecureRandom random = Utils.createFixedRandom(); // create the parameters AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance( "ElGamal", "BC"); apg.init(256, random); AlgorithmParameters params = apg.generateParameters(); AlgorithmParameterSpec dhSpec = params.getParameterSpec( DHParameterSpec.class); // create the keys KeyPairGenerator generator = KeyPairGenerator.getInstance("ElGamal", "BC"); generator.initialize(dhSpec, random); KeyPair pair = generator.generateKeyPair(); Key pubKey = pair.getPublic(); Key privKey = pair.getPrivate(); System.out.println("input : " + Utils.toHex(input)); // encryption step cipher.init(Cipher.ENCRYPT_MODE, pubKey, random); byte[] cipherText = cipher.doFinal(input); System.out.println("cipher: " + Utils.toHex(cipherText)); // decryption step cipher.init(Cipher.DECRYPT_MODE, privKey); byte[] plainText = cipher.doFinal(cipherText); System.out.println("plain : " + Utils.toHex(plainText)); } }
- 02-22-2012, 05:20 PM #2
Re: Uncompilable source code - Erroneous sym type: Utils.createFixedRandom?
Where is the Utils class defined? The compiler can not find its definition.
Is it in a package that you need to import?
- 02-22-2012, 05:31 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 18
- Rep Power
- 0
- 02-22-2012, 05:36 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Uncompilable source code - Erroneous sym type: Utils.createFixedRandom?
Then I would check in that book and see whether there's a resources section or web link to code associated with the examples.
- 02-22-2012, 05:37 PM #5
Re: Uncompilable source code - Erroneous sym type: Utils.createFixedRandom?
If you do not have the definitions for that class, you will have to figure out if there is a similar class in the Java SE classes and change the code to use the Java SE class.
Check the book's appendix or its website for the class's definition.
- 02-22-2012, 06:19 PM #6
Similar Threads
-
I want the source code of DUK's Bank , the example code in Java EE 5 Tutorial 2010
By zahra in forum New To JavaReplies: 16Last Post: 01-31-2012, 08:36 PM -
servlet include method copying sorce code and executing source code as output how to
By shamkuma2k in forum Advanced JavaReplies: 0Last Post: 08-07-2011, 08:32 PM -
Problem of getting erroneous IP address
By R O C K Y in forum Advanced JavaReplies: 1Last Post: 02-09-2009, 11:25 PM -
MavenJava - browse source code of all open source projects online
By jirkacelak in forum Java SoftwareReplies: 1Last Post: 11-28-2008, 06:27 PM -
The Utils
By JavaLovenJoe in forum New To JavaReplies: 1Last Post: 04-19-2008, 08:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks