Results 1 to 6 of 6
  1. #1
    Akirien is offline Member
    Join Date
    Feb 2012
    Posts
    18
    Rep Power
    0

    Default 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.

    Java 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));
        }
    }
    Thanks in advance :D

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    14,792
    Rep Power
    20

    Default 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?

  3. #3
    Akirien is offline Member
    Join Date
    Feb 2012
    Posts
    18
    Rep Power
    0

    Default Re: Uncompilable source code - Erroneous sym type: Utils.createFixedRandom?

    Quote Originally Posted by Norm View Post
    Where is the Utils class defined? The compiler can not find its definition.
    Is it in a package that you need to import?
    I dont know, I got this code from Beginning Cryptography for JAVA books. :(

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    10,438
    Rep Power
    16

    Default 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.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    14,792
    Rep Power
    20

    Default 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.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,918
    Rep Power
    16

    Default Re: Uncompilable source code - Erroneous sym type: Utils.createFixedRandom?

    Moving to New to Java. Inability to compile source code doesn't belong in Advanced Java.

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  2. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  3. Problem of getting erroneous IP address
    By R O C K Y in forum Advanced Java
    Replies: 1
    Last Post: 02-09-2009, 11:25 PM
  4. Replies: 1
    Last Post: 11-28-2008, 06:27 PM
  5. The Utils
    By JavaLovenJoe in forum New To Java
    Replies: 1
    Last Post: 04-19-2008, 08:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •