aspose file tools*
The moose likes Applets and the fly likes Problem in SecretKeyFactory Generation in Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Problem in SecretKeyFactory Generation in Applet" Watch "Problem in SecretKeyFactory Generation in Applet" New topic
Author

Problem in SecretKeyFactory Generation in Applet

Tariq Sultan
Greenhorn

Joined: Aug 08, 2002
Posts: 3
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in SecretKeyFactory Generation in Applet
 
Similar Threads
Encryption: Runtime Exception when run as JavaBean
Error in PrivateKey Encryption in Applet
exception from tripleDES encryption
Problem Urgent: Crypto using jsp - javabean
File encryption / decryption retaining line feeds