Question about Exception Error

I'm writing a small PBE program for a class project and I keep getting an InvalidKeySpecException that claims my char[ ] is not ASCII. Now I am under the impression that when a char value is entered it's in ASCII values... I've only put up a piece of my code, if needed I can put up the rest, it's fairly simple and easy to follow.
here is my terminal output (with a number of debug outputs):
Encryption Program Started
Getting Password
Input password (32 character max):
hello
Holdspot is: 6
Pass: hello
Holder: (shows string of char (0) values, verifies that the array was cleared)
Done getting password, pass is:
hello
Creating PBEKeySpec
My keySpec value is: hello
Creating Salt
createSalt entered
Done getting salt
Creating PBEParameterSpec
setParams entered
My iteration field is: 1500
Done getting param
My param iterations are: 1500
Creating SecretKey
createKey Entered
My keySpec value is: hello
InvalidKeySpecException: Password is not ASCII
java.security.spec.InvalidKeySpecException: Password is not ASCII
     at com.sun.crypto.provider.PBEKey.<init>(DashoA6275)
     at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(DashoA6275)
     at javax.crypto.SecretKeyFactory.generateSecret(DashoA6275)
     at Cryptography.createKey(Cryptography.java:141)
     at Cryptography.main(Cryptography.java:265)
     at __SHELL3.run(__SHELL3.java:7)
     at bluej.runtime.ExecServer.vmSuspend(ExecServer.java:178)
     at bluej.runtime.ExecServer.main(ExecServer.java:143)
java.security.spec.InvalidKeySpecException: Password is not ASCII
     at com.sun.crypto.provider.PBEKey.<init>(DashoA6275)
     at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(DashoA6275)
     at javax.crypto.SecretKeyFactory.generateSecret(DashoA6275)
     at Cryptography.createKey(Cryptography.java:141)
     at Cryptography.main(Cryptography.java:265)
     at __SHELL4.run(__SHELL4.java:7)
     at bluej.runtime.ExecServer.vmSuspend(ExecServer.java:178)
     at bluej.runtime.ExecServer.main(ExecServer.java:143)
here is my code to get the char array input:
    private char[] getPass () throws IOException{
        System.out.println("Input password (32 character max):");
        char[] holder = new char[maxChar];
        int holdspot=0;
        while ((holder[holdspot++] = (char) System.in.read()) != '\n') {};
        //Debug
        System.out.println("Holdspot is: "+holdspot);
        //End Debug
        char[] pass = new char[holdspot];
        System.arraycopy (holder, 0, pass, 0, holdspot);
        //clear our holder array
        for (int i=0; i<holder.length;i++){
            holder=0;
//Debug
System.out.print("Pass: ");
for (int i=0; i<holdspot;i++){
System.out.print(pass[i]);
System.out.print("\n");
System.out.print("Holder: ");
for (int i=0; i<holder.length;i++){
System.out.print(holder[i]);
System.out.print("\n");
//End Debug
//Comment back in for final version, screen clear
//System.out.flush();
return (pass);
here is my code at the point where the exception is thrown:
    private SecretKey createKey(PBEKeySpec keySpec)
    throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException{
        //Debug
        System.out.println("createKey Entered");
        char[] L = keySpec.getPassword();
        System.out.print("My keySpec value is: ");
         for (int i=0; i<L.length;i++){
            System.out.print(L);
//End Debug
SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey secKey = keyFac.generateSecret(keySpec);
return (secKey);

OK, got to Eclipse and reproduced the problem using your code.
Something about the way you were reading your password bugged me. I changed your code a bit to the following:import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
public class PBETest {
  static final int MAX_CHAR = 32;
  private char[] getPass() throws IOException {
    System.out.print("Input password ("+MAX_CHAR+" character max):");
    String s = new BufferedReader(new InputStreamReader(System.in)).readLine();
    char[] holder = s.toCharArray();
    int holdspot = (s.length()>MAX_CHAR?MAX_CHAR:s.length());
    //End Debug
    char[] pass = new char[holdspot];
    System.arraycopy(holder, 0, pass, 0, holdspot);
    //clear our holder array
    for (int i = 0; i < holder.length; i++) {
      holder[i] = 0;
    //Debug
    System.out.print("Pass: ");
    for (int i = 0; i < holdspot; i++) {
      System.out.print(pass);
System.out.print("\n");
System.out.print("Holder: ");
for (int i = 0; i < holder.length; i++) {
System.out.print(holder[i]);
System.out.print("\n");
//End Debug
//Comment back in for final version, screen clear
//System.out.flush();
return (pass);
private SecretKey createKey(PBEKeySpec keySpec)
throws NoSuchAlgorithmException, InvalidKeyException,
InvalidKeySpecException {
//Debug
System.out.println("createKey Entered");
char[] L = keySpec.getPassword();
System.out.print("My keySpec value is: ");
for (int i = 0; i < L.length; i++) {
System.out.print(L[i]);
//End Debug
SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey secKey = keyFac.generateSecret(keySpec);
return (secKey);
public static void main(String[] args) {
try {
PBETest ptest = new PBETest();
char[] pwd = ptest.getPass();
PBEKeySpec spec = new PBEKeySpec(pwd);
SecretKey sk = ptest.createKey(spec);
} catch (Exception e) {
e.printStackTrace();
}And now it works.
I don't know exactly why your "one char at a time from System.in" bugged me, and I don't know exactly why it didn't work - but that was the problem.
Grant

Similar Messages

  • [SOLVED] Question about GCC error messages.

    I'm currently taking a course in C programming, and I have  a question about the error messages returned by GCC.
    When ever i try to compile a program containing syntax errors, i get cryptic and not very helpfull error messages.
    If i try to compile:
    #include <stdio.h>
    int main(void)
    int i;
    i = 0
    return 0;
    I get following from GCC:
    error.c: In function â:
    error.c:8:2: error: expected â before â
    But shouldn't the message be something like:
    error.c: In function 'main':
    error.c:8:2: error: expected ; before 'return'
    or am I mistaken?
    /AcId
    Last edited by AcId (2010-10-13 17:48:19)

    Woah. That is very strange. I've never seen that before.
    I assume you're using Arch Linux. What text editor did you use to write the code? Which terminal application are you using?
    ...those questions are probably unrelated to the problem, but we might as well get them out of the way.

  • Question about UTL_FILE_DIR - Errors

    I have read several other postings about the error I am getting with UTL_FILE DIR:
    Cause: FDPSTP failed due to ORA-20102: Invalid Operation
    ORA-06512: at "APPS.XXHH_PAY_OUT_PS16", line 424
    ORA-06512: at line 1
    We have setup the parameter in V$Parameter and the directories related are all created with proper permissions.
    My first question is do the same directories need to be created on the db server as well?
    Our setup is as follows: RAC environment 2 app servers, 2 db servers. The app servers have the directory that the error is coming out of. The directories are not on the db servers.
    The line of code causing our issue:
    fp := utl_file.fopen(v_directory, v_file_name,'w');

    My first question is do the same directories need to be created on the db server as well?Yes, or the directories should be accessible from the database tier node.
    Our setup is as follows: RAC environment 2 app servers, 2 db servers. The app servers have the directory that the error is coming out of. The directories are not on the db servers.
    The line of code causing our issue:
    fp := utl_file.fopen(v_directory, v_file_name,'w');Please mount the directory on the database servers and check then.
    How do the UTL_FILE Functionality Implement in a RAC Environment? [ID 1080391.1]
    SYS.Utl_file Is Generating ORA-29280:Utl_file.Invalid_path In Rac Environment Only. [ID 567594.1]
    Thanks,
    Hussein

  • Question about Java Errors

    I have some questions about some java errors
    1. what kind of errors are contained in Error class?
    2.does this class contain only runtime errors?
    3. if the question number 2 is positive, what about InstantiationError which is a compile error and is a subclass of Error.
    4.When our program is out of memory, which processes are done for an error to be produced. is the error actually from OS or VM?

    I have some questions about some java errors
    1. what kind of errors are contained in Error class?An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.
    2.does this class contain only runtime errors?No
    3. if the question number 2 is positive, what about
    InstantiationError which is a compile error and is a
    subclass of Error.
    4.When our program is out of memory, which processes
    are done for an error to be produced. is the error
    actually from OS or VM?Various - both, depending on where the error occurred.

  • Question about Correcting Errors in the Converted Model

    Hi,
    I've used SQL Developer (v1.5.1) to capture (offline) the DDL from a Sybase 12 DB and have converted this to Oracle, which all seemed to run ok. However, I noticed some errors in the Migration Log. None of them have the prefix 'Parse Exception' so, according to the online help, no manual intervention is required to resolve them.
    I don't even know if the contents of the migration log are a problem, generally they can be grouped under one of the three headings below.
    "*Multiple Limitations for Stored Procedure* extUpdateExtSuccess 03-SEP-08-16:09:41"
    "*Translation limitation* '@@ERROR' encountered on Stored Procedure CorporateActions.dbo.extBMDeleteBatchSchedule line 14 column 4 03-SEP-08-14:53:23"
    "*Index* 'XPKSpinOffExt' on table 'SpinOffExt' *has been dropped as it is a duplicate of a constraint* 03-SEP-08-14:39:26"
    Are these errors something I need to do something about before I try generating the DDL? Are they related to Sybase (which I know very little about).
    Online help is not very helpful on this subject.
    Thanks,
    Antony

    Hi, Hareesh
    I agree. But that is how it is defined now by someone else. It is hard to change it as he defines the same structure on the receiving side. I didn't want to change the receiving structure as it touches the proxy code too. So I want to make something short and sweet.
    Basically the data looks like this:
    11,222
    55,666
    The result xml should be something like:
    <JOB>
      <Msg>
         <Transaction>
            <DATA>
               11
               222
            </DATA>
         </Transaction>
         <Transaction>
            <DATA>
              55
              666
            </DATA>
          </Transaction>
      </MSG>
    </JOB>
    I know either the DATA has no meaning and it's giving me a headache ... but that's how it's done and I don't want to rock the boat too much. There are lots of mapping that I have changed otherwise.
    Thanks,
    Jonathan.

  • Forms question  about exceptions

    Hello,
    I am a newbie and hence my question may find very basic, please help me.
    I have a Pl/sql code where I am executing a queryand if the query doesn't retrieve any values I need to show a message.
    My code is something like this:
    select id from table into tmpid where id=:val_id
    some code here
    CALL_form(url);
    If the query fails I need to show a message, how can I do this. Forgive me for my knowledge in forms, as I am a newbie.
    Thanks in advance.
    Newbie

    Declare
      Found1  varchar2(1);
    Begin
      ...whatever code you need here...
      begin
        select 'Y' into Found1
          from table where id=:val_id;
        exception when no_data_found then null;
      end;
      If Found1 is null then
        Message('No can do!!!');
        Raise form_trigger_failure;
      End if;
      ...some code here...
      Call_form(url);
    End;

  • Question about exceptions in function module GUI_DOWNLOAD

    To all,
    I add the function module 'GUI_DOWNLOAD' in the ABAP report program. After the user download the data to excel, the program also displays a report on the screen for print output.
    If the user keep the excel file open and tries to replace the file on download, the program gives an error message 'Access to file denied' and the program ends without displaying a report on the screen.
    Is there any way not to end the program even if download is failed?
    I would like the program displays a report after it gives an error message.
    So I am trying to use exceptions. But if I code to give messages, the programs ends as above. And if I just make exit when it happens, no error message and the program displays a report but the user don't know if the excel file was updated or not.
    Could anybody kindly let me know how to code exceptions and messages if it is possible the program works I hope.
    Thank you very much in advance.
    Best regards,
    Miki Komatsu

     I figured out how to do that.
      Thanks.
      Best regards,
      Miki

  • Simple questions about exceptions

    why use try catch with new File("filename") but not with x??

    ArrayIndexOutOfBoundsException is unchecked.
    IOException is checked.
    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
    Here's a quick overview of exceptions:
    The base class for all exceptions is Throwable. Java provides Exception and Error that extend Throwable. RuntimeException (and many others) extend Exception.
    RuntimeException and its descendants, and Error and its descendants, are called unchecked exceptions. Everything else is a checked exception.
    If your method, or any method it calls, can throw a checked exception, then your method must either catch that exception, or declare that your method throws that exception. This way, when I call your method, I know at compile time what can possibly go wrong and I can decide whether to handle it or just bubble it up to my caller. Catching a given exception also catches all that exception's descendants. Declaring that you throw a given exception means that you might throw that exception or any of its descendants.
    Unchecked exceptions (RuntimeException, Error, and their descendants) are not subject to those restrictions. Any method can throw any unchecked exception at any time without declaring it. This is because unchecked exceptions are either the sign of a coding error (RuntimeException), which is totally preventable and should be fixed rather than handled by the code that encounters it, or a problem in the VM, which in general can not be predicted or handled.

  • Question about an error in Crimson Editor

    I copied this code from a Deitel book into the code window of Crimson Editor just to see if it worked(it's a piece of code that outputs a window like a GUI). When I ran the program the error message in the console window on the bottom said:
    java.lang.NoClassDefFound: Array
    Exception in thread "main"
    Terminated with exit code 1What I was wondering is that the editor isn't highlighting anything in the code editor window to tell me where the error is. I guess that's what I was at least expecting it to do. Or is this particular error not going to do that?

    I don't wish to sound like a bastard (well, maybe a little), but I'd guess the Crimson Editor forums would yeild better results then this forum.
    http://www.crimsoneditor.com/board/CrazyWWWBoard.cgi?db=board0

  • Quick Question About This Error "The movie "thedarkknight" could not be use

    This is the Error:"The Movie "The Dark Knight" could not be used because the original file could not be found. would you like to locate it?"
    Accidently Deleted my I-tunes folder, and its not in my recycle bin, read all the support pages, and it told me if its not backed up and its not on my computer I have to re buy all my movies? <-----IS THIS TRUE?
    Is there an option to re-download my already payed for content?
    Is my content gone forever? and I can only get it back by buying it again?
    Please help thanks.
    Message was edited by: BunnyCarrot

    First thing - this is a worldwide forum so anyone who knows the answer could be asleep when you post this, so expecting a reply within thirty minutes and bumping when it doesn't arrive, is unreasonable.
    To answer your questions though;
    BunnyCarrot wrote:
    ... if its not backed up and its not on my computer I have to re buy all my movies? <-----IS THIS TRUE?</div>
    Yes, afraid so.
    Is there an option to re-download my already payed for content?
    No
    Is my content gone forever? and I can only get it back by buying it again?
    Yes.
    Phil (in the UK)

  • A question about an error after changing FSB

    Here is what I am running
    MSI K7T266 Pro
    AMD Athlon Thunderbird 1.4ghz processor
    512 DDR RAM
    Geforce 3 Ti 500
    Intel 21041-Based PCI Ethernet Adapter (Generic) #2
    Now I loaded my FSB at 100 and it runs fine but only at 1.050 ghz instead of 1.4.
    I try running at 133 FSB and it runs at 1.4 till I try to install anything and it crashes my computer and corrupts my HDD and gives me a 'serious error' message of:
    BCCode : d1     BCP1 : FFFFFFA3     BCP2 : 00000010     BCP3 : 00000001    
    BCP4 : F81EB965     OSVer : 5_1_2600     SP : 0_0     Product : 768_1  
    Now I want to know what this means?
    I cleared my CMOS and now I only got the error message once when I tried to install the drivers for my sound card.  and I can install DOOM 3 now without getting the reboot and 'serious error' message.

    Quote
    Originally posted by GuyOne
    Yes, PC2100.
    How do I run that memtest program? I cannot figure it out.
    The latest memtest86 installer/extractor creates its own boot diskette (with its own boot files).  Just boot with the diskette, memtest86 does its thing, no user interaction required.
    Alternatively, an .ISO image is now available that is suitable for creating a self-booting memtest86 CD.

  • Question about dll. error message when loading - PSE 6

    I have PSE 6 and suddenly get the following error message when I open PSE:  Organizer-Photoshop Element PhotoshopElementsOrganizer exe- entry point fot found.  CFBundle Copy File TypeForFileData could not be located in dynamic linc library core foundation.dll.
    No idea what that means, what happened and how to fix this.
    Is there anybody that can give advise to a non-computer literate person????
    Help would be greatly appreciated.

    See post #6 in this thread for a likely solution:
    http://www.elementsvillage.com/forums/showthread.php?t=50471

  • Question about Exception!

    class A
    public void f() throws Myexcption
    class B extends A
    public void f() throws [Myexception][devied exception from Myexception]
    Why B.f() can only throw less exceptions than A.f()?
    if A temp = new B();
    temp.f() will perform the B.f()'s defination. And if I defined B.f() as
    public void f() throws AnotherException
    throw AnotherException;
    It will has nothing to do with A.f().
    Why did the designer design the less exception throwwing rules?
    Thanks

    class MyFirstException extends Exception {}
    class MySecondException extends MyFirstException {}
    class A {
      public void f() throws MyFirstException { ... }
    class B extends A {
      public void f() throws MySecondException { ... }
    Why B.f() can only throw less exceptions than A.f()?The reason is one of decoupling. If you write code to the contract of A but are actually using an instance of B and the compiler allowed new exceptions to be thrown (not inheriting from the exceptions declared on the original contract) - you would have no way of knowing which other exceptions you must catch. Therefore by enforcing that an overriding method must throw only exceptions within the inheritance hierarchy of the original contract you can be certain to have caught all possible exceptions.
    EG
    A a = new B();
    try {
      a.f();
    } catch(MyFirstException e) { ... }--
    Talden

  • Question about Exception stack

    Hello,
    I get the following exception stack and it is not the first time that I get this "ClassName.<init>".
    What does the "init" mean?
    Thanks in advance,
    Balteo.
    oracle.xquery.XQException:  Too many arguments for function compare
         [java]      at oracle.xquery.PreparedXQuery.<init>(PreparedXQuery.java:63)
         [java]      at oracle.xquery.XQueryContext.prepareXQuery(XQueryContext.java:140)
         [java]      at com.agilience.sharenet.app.sgbdo.PPersistenceOracle.executeQuery(PPersistenceOracle.java:214)
         [java]      at com.agilience.sharenet.app.sgbdo.PPersistenceOracle.getAnonymousId(PPersistenceOracle.java:369)
         [java]      at com.agilience.sharenet.app.bl.persistence.PPersistenceModel.getAnonymousId(PPersistenceModel.java:112)

    When an exception occurs inside the constructor for the class, the stack trace refers to the constructor as <init>. <init> is the internal name that java uses to refer to constructors for a class.

  • QUESTION ABOUT AN ERROR MESSAGE UPON STARTUP OF COMPUTER

    I receive an error message at startup that says:
    "an unexpected error occured while trying to load the microsolf framework library"
    Is this causing damage to my computer? If so, what should I do?
    I had my old info from my previous mac transfered to this new one.

    Any help looking through these?
    http://discussions.apple.com/search.jspa?objID=f808&search=Go&q=error+48

Maybe you are looking for