Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

help understanding this strange runtime error

807606Apr 17 2007 — edited Apr 17 2007
Hi.
I have a class to generate a random password.
Let's say the output of that class is :
y0v{fwu-ss}5

//this is what Utils.unscramble returns
char[] password =  new char[] {
121,
48,
118,
123,
102,
127,
102,
119,
117,
45,
115,
115,
125,
53,
};
if i use the variable "password" as this:
.......
ks.setKeyEntry(alias, key1, password, chain);
ks.store(os, password);
....
i get an exception:
Key protection algorithm not found: java.security.UnrecoverableKeyException: Encrypt Private Key failed: getSecretKey failed: Password is not ASCII - reported by ks.setKey (...) code

and

Failed to encrypt safe contents entry: java.io.IOException: getSecretKey failed: Password is not ASCII - reported by ks.store(...).

At this point i had no clue why the exceptions were happening.
Changing the code above by
.......
ks.setKeyEntry(alias, key1, "y0v{fwu-ss}5".toCharArray(), chain);
ks.store(os, "y0v{fwu-ss}5".toCharArray());
....
For my disbelief the code works like suposed to, no errors or exceptions at all.
Now, what i'm missing here?

I even tryed to do this with no luck:
char[] result = Utils.unscramble();
String r = new String(result);  
String password = r.trim();
....
ks.store(...., password.toCharArray(),...);
Why is still complaining about password not being ascii ?
Thank you.

Message was edited by:
noe.rocha
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 15 2007
Added on Apr 17 2007
2 comments
229 views