Results 1 to 8 of 8
  1. #1
    talk2devid is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Question Help Needed Regarding java.security.NoSuchAlgorithmException

    Respected members,

    I have a program -

    Java Code:
    import java.io.*;
    import java.security.*;
    
    public class TestSerial {
    	
    	public static void main(String args[])
    	{
    		String serialNumberEncoded ;
    		String fullNameString ;
    			
          String calculateSecurityHash(String stringInput, String algorithmName )
             throws java.security.NoSuchAlgorithmException 		{
        	  
        	  
    		
    		String hexMessageEncode = "";
    	    byte[] buffer = stringInput.getBytes();
    	    java.security.MessageDigest messageDigest = java.security.MessageDigest.getInstance(algorithmName);
    	    messageDigest.update(buffer);
    	    byte[] messageDigestBytes = messageDigest.digest();
    	    
    	    for (int index=0; index < messageDigestBytes.length ; index ++) 
    	    {
    	         int countEncode = messageDigestBytes[index] & 0xff;
    	         if (Integer.toHexString(countEncode).length() == 1) hexMessageEncode = hexMessageEncode + "0";
    	         hexMessageEncode = hexMessageEncode + Integer.toHexString(countEncode);
    	    }
    	    return hexMessageEncode;
    	   }
    	    
    	    serialNumberEncoded = calculateSecurityHash(fullNameString,"MD2") +  calculateSecurityHash(fullNameString,"MD5") +
    		 calculateSecurityHash(fullNameString,"SHA1");
    	    String serialNumber = ""
    		    + serialNumberEncoded.charAt(32)
    		    + serialNumberEncoded.charAt(76)
    		    + serialNumberEncoded.charAt(100)
    		    + serialNumberEncoded.charAt(50)
    		    + "-"
    		    + serialNumberEncoded.charAt(2)
    		    + serialNumberEncoded.charAt(91)
    		    + serialNumberEncoded.charAt(73)
    		    + serialNumberEncoded.charAt(72)
    		    + serialNumberEncoded.charAt(98)
    		    + "-"
    		    + serialNumberEncoded.charAt(47)
    		    + serialNumberEncoded.charAt(65)
    		    + serialNumberEncoded.charAt(18)
    		    + serialNumberEncoded.charAt(85)
    		    + "-"
    		    + serialNumberEncoded.charAt(27)
    		    + serialNumberEncoded.charAt(53)
    		    + serialNumberEncoded.charAt(102)
    		    + serialNumberEncoded.charAt(15)
    		    + serialNumberEncoded.charAt(99); 
    		String serialNumberEncoded = registrationAppSerialGenerationReversal.calculateSecurityHash(fullNameString,"MD2")
    	    + registrationAppSerialGenerationReversal.calculateSecurityHash(fullNameString,"MD5")
    	    + registrationAppSerialGenerationReversal.calculateSecurityHash(fullNameString,"SHA1");
    	 
    	String serialNumberCalc = ""
    	    + serialNumberEncoded.charAt(32)
    	    + serialNumberEncoded.charAt(76)
    	    + serialNumberEncoded.charAt(100)
    	    + serialNumberEncoded.charAt(50)
    	    + "-"
    	    + serialNumberEncoded.charAt(2)
    	    + serialNumberEncoded.charAt(91)
    	    + serialNumberEncoded.charAt(73)
    	    + serialNumberEncoded.charAt(72)
    	    + serialNumberEncoded.charAt(98)
    	    + "-"
    	    + serialNumberEncoded.charAt(47)
    	    + serialNumberEncoded.charAt(65)
    	    + serialNumberEncoded.charAt(18)
    	    + serialNumberEncoded.charAt(85)
    	    + "-"
    	    + serialNumberEncoded.charAt(27)
    	    + serialNumberEncoded.charAt(53)
    	    + serialNumberEncoded.charAt(102)
    	    + serialNumberEncoded.charAt(15)
    	    + serialNumberEncoded.charAt(99);
    	 
    	if (serialNumber.equals(serialNumberCalc))
    	    System.out.println("Serial MATCH");
    	else
    	    System.out.println("Serial MIS-MATCH");
    		
    	}
    
    	
    	 
    }
    The Program Will generate The Following Error, And I can't Figure Out Why The Problem Will Generate -

    Java Code:
    Multiple markers at this line
    	- Syntax error on token ",", ; expected
    	- Syntax error on token "(", ; expected
    	- Syntax error, insert ";" to complete 
    	 LocalVariableDeclarationStatement
    Did I missed to add any header file ? or There is some Syntax error. Please suggest.

    Best Regards
    David

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default

    Count your curly brackets, they have to match; as it is now you're trying to define another method in the body of your main method body. You can't do that in Java.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    talk2devid is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Dear Jos,

    Java Code:
    as it is now you're trying to define another method in the body of your main method body
    Can i Move The method out side of the static main function ? Please Suggest.


    Regards
    David
    Last edited by talk2devid; 12-18-2010 at 08:12 AM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by talk2devid View Post
    Can i Move The method out side of the static main function ? Please Suggest.
    You have to do that because as your code is now it doesn't compile; the structure of your class should be like this (pay attention to the curly brackets):

    Java Code:
    public class TestSerial {
    	
       public static void main(String args[]) { ... }
    
       String calculateSecurityHash(String stringInput, String algorithmName )
             throws java.security.NoSuchAlgorithmException { ... }
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    talk2devid is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Dear Jos,

    I Have Tried your Solution, Still It Gives Error. I am Attaching The File. Kindly Examine the File. Please Check And Please Please Let Me Know The Issue.

    I am Looking Forward To Your Reply.

    ~David
    Attached Files Attached Files

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by talk2devid View Post
    I Have Tried your Solution, Still It Gives Error. I am Attaching The File. Kindly Examine the File. Please Check And Please Please Let Me Know The Issue.
    I copied your file here:

    Java Code:
    import java.io.*;
    import java.security.*;
    
    public class TestSerial2 {
    	public static void main(String args[])
    	{
    		String serialNumberEncoded ;
    		String fullNameString ;
    
    	}
    
          String calculateSecurityHash(String stringInput, String algorithmName )
             throws java.security.NoSuchAlgorithmException
             {
    
             	String hexMessageEncode = "";
    	    byte[] buffer = stringInput.getBytes();
    	    java.security.MessageDigest messageDigest = java.security.MessageDigest.getInstance(algorithmName);
    	    messageDigest.update(buffer);
    	    byte[] messageDigestBytes = messageDigest.digest();
    
    	    for (int index=0; index < messageDigestBytes.length ; index ++)
    	    {
    	         int countEncode = messageDigestBytes[index] & 0xff;
    	         if (Integer.toHexString(countEncode).length() == 1) hexMessageEncode = hexMessageEncode + "0";
    	         hexMessageEncode = hexMessageEncode + Integer.toHexString(countEncode);
    	    }
    	    return hexMessageEncode;
    
    
    	    serialNumberEncoded = calculateSecurityHash(fullNameString,"MD2") +  calculateSecurityHash(fullNameString,"MD5") +
    		 calculateSecurityHash(fullNameString,"SHA1");
    	    String serialNumber = ""
    		    + serialNumberEncoded.charAt(32)
    		    + serialNumberEncoded.charAt(76)
    		    + serialNumberEncoded.charAt(100)
    		    + serialNumberEncoded.charAt(50)
    		    + "-"
    		    + serialNumberEncoded.charAt(2)
    		    + serialNumberEncoded.charAt(91)
    		    + serialNumberEncoded.charAt(73)
    		    + serialNumberEncoded.charAt(72)
    		    + serialNumberEncoded.charAt(98)
    		    + "-"
    		    + serialNumberEncoded.charAt(47)
    		    + serialNumberEncoded.charAt(65)
    		    + serialNumberEncoded.charAt(18)
    		    + serialNumberEncoded.charAt(85)
    		    + "-"
    		    + serialNumberEncoded.charAt(27)
    		    + serialNumberEncoded.charAt(53)
    		    + serialNumberEncoded.charAt(102)
    		    + serialNumberEncoded.charAt(15)
    		    + serialNumberEncoded.charAt(99);
    		String serialNumberEncoded = registrationAppSerialGenerationReversal.calculateSecurityHash(fullNameString,"MD2")
    	    + registrationAppSerialGenerationReversal.calculateSecurityHash(fullNameString,"MD5")
    	    + registrationAppSerialGenerationReversal.calculateSecurityHash(fullNameString,"SHA1");
    
    	String serialNumberCalc = ""
    	    + serialNumberEncoded.charAt(32)
    	    + serialNumberEncoded.charAt(76)
    	    + serialNumberEncoded.charAt(100)
    	    + serialNumberEncoded.charAt(50)
    	    + "-"
    	    + serialNumberEncoded.charAt(2)
    	    + serialNumberEncoded.charAt(91)
    	    + serialNumberEncoded.charAt(73)
    	    + serialNumberEncoded.charAt(72)
    	    + serialNumberEncoded.charAt(98)
    	    + "-"
    	    + serialNumberEncoded.charAt(47)
    	    + serialNumberEncoded.charAt(65)
    	    + serialNumberEncoded.charAt(18)
    	    + serialNumberEncoded.charAt(85)
    	    + "-"
    	    + serialNumberEncoded.charAt(27)
    	    + serialNumberEncoded.charAt(53)
    	    + serialNumberEncoded.charAt(102)
    	    + serialNumberEncoded.charAt(15)
    	    + serialNumberEncoded.charAt(99);
    
    	if (serialNumber.equals(serialNumberCalc))
    	    System.out.println("Serial MATCH");
    	else
    	    System.out.println("Serial MIS-MATCH");
    }
    }
    Your main method doesn't do anything, it just defines two local String variables and terminates. What were the issues you experienced?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    talk2devid is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Your main method doesn't do anything, it just defines two local String variables and terminates. What were the issues you experienced?
    Sorry. I just want to call the function into my main function. so that, the main function will call the sub-function and run the program.

    Basically I want to call calculateSecurityHash() method inside the public static void main.


    The Output may look like the this. (Please Check The Attachment).

    ~David
    Attached Thumbnails Attached Thumbnails Help Needed Regarding java.security.NoSuchAlgorithmException-serial.jpg  
    Last edited by talk2devid; 12-18-2010 at 11:15 AM. Reason: Output Image Added

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by talk2devid View Post
    Sorry. I just want to call the function into my main function. so that, the main function will call the sub-function and run the program.
    Well, call the method from your main( ... ) method; note that the other method isn't static so you need to have an object to call that method on; I don't know if you want that (you can also make the other method static so no objects are needed).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Security & Java
    By ajeeb in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 12-07-2010, 04:07 PM
  2. Java Security Policy
    By divot in forum Advanced Java
    Replies: 1
    Last Post: 11-16-2010, 03:23 AM
  3. NoSuchAlgorithmException
    By soccermiles in forum New To Java
    Replies: 7
    Last Post: 04-26-2010, 04:35 AM
  4. Java security program
    By bhaumik1987 in forum New To Java
    Replies: 7
    Last Post: 02-09-2010, 02:28 PM
  5. Java security
    By Zosden in forum Java Applets
    Replies: 43
    Last Post: 08-02-2008, 02:10 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
  •