Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Problem in SecretKeyFactory Generation in Applet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am facing a problem while using security API in applets. What I am using is Bouncy Castle Crypto API. The exact place wher i get the error is where i create the SecretKeyFactory instance
( I have coloured that plcae below ). This code worked fine in applet with IAIK API but giving problem with Bouncy Castle API.

/**********************************************?
private byte[] makeEncryptedPrivateKey(PrivateKey priKey, String password){
String alg = "1.2.840.113549.1.12.1.3";
String provider = "BC";
PBEKeySpec pbeSpec = null;
SecretKeyFactory keyFact = null;
Cipher cipher = null;
byte[] wrappedKey = null;
byte[] encryptKey = null;
EncryptedPrivateKeyInfo pInfo = null;
try {
byte[] salt = new byte[10];
int iterationCount = 100;
PBEParameterSpec defParams = new PBEParameterSpec(salt, iterationCount);
AlgorithmParameters params = AlgorithmParameters.getInstance(alg, provider);
params.init(defParams);
pbeSpec = new PBEKeySpec(password.toCharArray());
keyFact = SecretKeyFactory.getInstance(alg,provider);
cipher = Cipher.getInstance(alg, provider);
cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), params);
wrappedKey = cipher.wrap(priKey);
pInfo = new EncryptedPrivateKeyInfo(params, wrappedKey);
encryptKey = pInfo.getEncoded();
}
catch (Exception ex) {
ex.printStackTrace();
}
return encryptKey;
}

When execution reaches at this point I receive the following error:
/*******************************************/

java.security.NoSuchProviderException: JCE cannot authenticate the provider BC java.util.jar.JarException:
http://tariq:8080/examples/TestApplet.jar is not signed by a trusted signer.
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.SecretKeyFactory.getInstance(DashoA6275)
at com.fourthhs.cs.applets.TestApplet.makeEncryptedPrivateKey(TestApplet.java:117)
at com.fourthhs.cs.applets.TestApplet.init(TestApplet.java:47)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


It shows as if I dont have the trusted Certs to sign the jar but its not the actual case, the Certs are trusted and verified. Morover, before this
piece of code I have generated an RSA key pair and that was generated successfully.
with the same
Will anybody be kind enough to guide me through this problem.

Regards,




(Tariq Sultan)
 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic