Current Position:Home > Exception in thread "Thread-4" java.lang.IllegalAccessError

Exception in thread "Thread-4" java.lang.IllegalAccessError

Update:10-11Source: network consolidation
Advertisement
Hi All,
I am getting this error at run-time while trying to run below code
Exception in thread "Thread-4" java.lang.IllegalAccessError
CODE:
================================
* FileName : UMAC.java *
* Program Details : For getting Signed data. *
* Invoked From : SignedDataImpl.java *
package sfmsbr.bankapi;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Enumeration;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import com.ibm.misc.BASE64Decoder;
import com.ibm.misc.BASE64Encoder;
import sun.security.pkcs.ContentInfo;
import sun.security.pkcs.PKCS7;
import sun.security.pkcs.PKCS9Attribute;
import sun.security.pkcs.PKCS9Attributes;
import sun.security.pkcs.SignerInfo;
import com.ibm.security.util.DerOutputStream;
/*import sun.security.x509.AlgorithmId;*/
import com.ibm.security.x509.AlgorithmId;
/*import sun.security.x509.X500Name;*/
import com.ibm.security.x509.X500Name;
/*import com.ibm.jsse.IBMJSSEProvider;*/
import org.apache.harmony.security.asn1.DerInputStream;
import com.cs.common.Utilities;
import com.sun.net.ssl.internal.ssl.Provider;
/*import javax.net.ssl.*;*/
import sun.security.pkcs.*;
public class UMAC
private static String storetype = null;
private static String storepath = null;
private static char keyPassword[] = null;
private static char filePassword[] = null;
private static String alias = null;
private static X509Certificate x509 = null;
private static Certificate certs[] = null;
private static final String digestAlgorithm = "SHA256";
private static final String signingAlgorithm = "SHA256withRSA";
private static Key key = null;
private static KeyPair pair = null;
private static KeyStore keystore = null;
private static PrivateKey priv = null;
private static PublicKey pub = null;
private static String signedData = null;
File certificateFile;
private static String fileName = "";
private static final String ALGORITHM = "PBEWithSHA256AndDes";
private String characterEncoding;
private Cipher encryptCipher;
private Cipher decryptCipher;
private BASE64Encoder base64Encoder = new BASE64Encoder();
private BASE64Decoder base64Decoder = new BASE64Decoder();
* Constructor to initialize the Parameters used
* @param s file name/path
* @param s1 is file password
* @param s2 is key password
* @param s3 is alias name
* @throws IOException
public UMAC(String s, String s1, String s2, String s3) throws IOException
try {
String dkeyPassword = Utilities.decodeDBPwd(s2);
String dFilePassword = Utilities.decodeDBPwd(s1);
keyPassword = (new String(dkeyPassword)).toCharArray();
filePassword = (new String(dFilePassword)).toCharArray();
alias = s3;
fileName = s;
} catch (Exception e) {
e.printStackTrace();
* method will prepare the digital signature for the message received as argument and returns the digital signature
* @param s the message to prepare signed data
* @return signed data prepard for the message received
* @throws NoSuchAlgorithmException
* @throws InvalidKeyException
* @throws IllegalBlockSizeException
* @throws NoSuchProviderException
* @throws BadPaddingException
* @throws NoSuchPaddingException
* @throws Exception
public String getSingedData(String s) throws NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, NoSuchProviderException, BadPaddingException, NoSuchPaddingException, Exception
Security.addProvider(new Provider()); // addProvider(Provider provider).. Adds a provider to the next position available.
System.out.println("reached here a");
certificateFile = new File(fileName);
/*keystore = KeyStore.getInstance("pkcs12", "SunJSSE");*/
keystore = KeyStore.getInstance("pkcs12", "IBMJCE");
System.out.println("reached here b");
BASE64Encoder base64encoder = new BASE64Encoder();
System.out.println("reached here ba");
keystore.load(new FileInputStream(certificateFile), filePassword);
System.out.println("reached here bb");
Enumeration enumeration = keystore.aliases();
do {
if(!enumeration.hasMoreElements())
break;
String s1 = enumeration.nextElement().toString();
if(keystore.isKeyEntry(s1))
alias = s1;
} while(true);
System.out.println("reached here c");
pair = getPrivateKey(keystore, alias, keyPassword);
priv = pair.getPrivate();
String s2 = base64encoder.encode(priv.getEncoded());
if(keystore.isKeyEntry(alias))
certs = keystore.getCertificateChain(alias);
if(certs[0] instanceof X509Certificate)
x509 = (X509Certificate)certs[0];
if(certs[certs.length - 1] instanceof X509Certificate)
x509 = (X509Certificate)certs[certs.length - 1];
} else
if(keystore.isCertificateEntry(alias))
Certificate certificate = keystore.getCertificate(alias);
if(certificate instanceof X509Certificate)
x509 = (X509Certificate)certificate;
certs = (new Certificate[] {
x509
} else {
throw new Exception(alias + " Wrong alias, Please Check");
AlgorithmId aalgorithmid[] = {
AlgorithmId.get("SHA256")
byte abyte0[] = s.getBytes("UTF8");
System.out.println("reached here d");
MessageDigest messagedigest = MessageDigest.getInstance("SHA256");
messagedigest.update(abyte0);
byte abyte1[] = messagedigest.digest();
PKCS9Attribute apkcs9attribute[] = {
new PKCS9Attribute(PKCS9Attribute.CONTENT_TYPE_OID, ContentInfo.DATA_OID), new PKCS9Attribute(PKCS9Attribute.SIGNING_TIME_OID, new Date()), new PKCS9Attribute(PKCS9Attribute.MESSAGE_DIGEST_OID, abyte1)
PKCS9Attributes pkcs9attributes = new PKCS9Attributes(apkcs9attribute);
Signature signature = Signature.getInstance("SHA256withRSA", "SunJSSE");
signature.initSign(priv);
signature.update(pkcs9attributes.getDerEncoding());
byte abyte2[] = signature.sign();
ContentInfo contentinfo = null;
contentinfo = new ContentInfo(ContentInfo.DATA_OID, null);
X509Certificate ax509certificate[] = {
x509
java.math.BigInteger biginteger = x509.getSerialNumber();
SignerInfo signerinfo = new SignerInfo(new X500Name(x509.getIssuerDN().getName()), biginteger, AlgorithmId.get("SHA256"), pkcs9attributes, new AlgorithmId(AlgorithmId.RSAEncryption_oid), abyte2, null);
SignerInfo asignerinfo[] = {
signerinfo
PKCS7 pkcs7 = new PKCS7(aalgorithmid, contentinfo, ax509certificate, asignerinfo);
DerOutputStream deroutputstream = new DerOutputStream();
pkcs7.encodeSignedData(deroutputstream);
byte abyte3[] = deroutputstream.toByteArray();
String s3 = new String(abyte3);
BASE64Encoder base64encoder1 = new BASE64Encoder();
String s4 = base64encoder1.encodeBuffer(abyte3);
BASE64Decoder base64decoder = new BASE64Decoder();
System.out.println("reached here e");
byte abyte4[] = base64decoder.decodeBuffer(s4);
PKCS7 pkcs7_1 = new PKCS7(abyte4);
SignerInfo asignerinfo1[] = null;
if(pkcs7_1.getContentInfo().getContentBytes() == null)
byte abyte5[] = s.getBytes("UTF8");
asignerinfo1 = pkcs7_1.verify(abyte5);
} else
asignerinfo1 = pkcs7.verify();
if(asignerinfo1 == null) {
throw new Exception("Signature failed verification, data has been tampered");
} else {
Utilities.log(3, "asignerinfo1 is not null Verification OK>>" + new Date(System.currentTimeMillis()), "UMAC", "run");
return s4;
* gets the private key for opening the signing file
* @param keystore1
* @param s is file path
* @param ac
* @return keypair
* @throws Exception
public KeyPair getPrivateKey(KeyStore keystore1, String s, char ac[]) throws Exception
PublicKey publickey;
System.out.println("inside UMAC.getPrivateKey");
key = keystore1.getKey(s, ac);
System.out.println("key --->" +key);
if(!(key instanceof PrivateKey))
return null;
Certificate certificate = keystore1.getCertificate(s);
publickey = certificate.getPublicKey();
System.out.println("Returning from UMAC.getPrivateKey : publickey is --->" +publickey);
return new KeyPair(publickey, (PrivateKey)key);
===========================================
Its compiling properly but at run-time it's showing below error
OUTPUT:
===========================================
reached here a
reached here b
reached here ba
Exception in thread "Thread-4" java.lang.IllegalAccessError
at sun.security.util.DerInputStream.init(Unknown Source)
at sun.security.util.DerInputStream.<init>(Unknown Source)
at sun.security.rsa.RSAPublicKeyImpl.parseKeyBits(Unknown Source)
at sun.security.x509.X509Key.decode(X509Key.java:396)
at sun.security.x509.X509Key.decode(X509Key.java:408)
at sun.security.rsa.RSAPublicKeyImpl.<init>(Unknown Source)
at sun.security.rsa.RSAKeyFactory.generatePublic(Unknown Source)
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(Unknown Source)
at java.security.KeyFactory.generatePublic(KeyFactory.java:145)
at com.ibm.security.x509.X509Key.buildX509Key(X509Key.java:278)
at com.ibm.security.x509.X509Key.parse(X509Key.java:189)
at com.ibm.security.x509.X509Key.parse(X509Key.java:215)
at com.ibm.security.x509.CertificateX509Key.<init>(CertificateX509Key.java:112)
at com.ibm.security.x509.X509CertInfo.parse(X509CertInfo.java:966)
at com.ibm.security.x509.X509CertInfo.<init>(X509CertInfo.java:236)
at com.ibm.security.x509.X509CertInfo.<init>(X509CertInfo.java:222)
at com.ibm.security.x509.X509CertImpl.parse(X509CertImpl.java:2285)
at com.ibm.security.x509.X509CertImpl.<init>(X509CertImpl.java:227)
at com.ibm.security.x509.X509CertImpl.<init>(X509CertImpl.java:213)
at com.ibm.security.pkcs12.CertBag.decode(CertBag.java:599)
at com.ibm.security.pkcsutil.PKCSDerObject.decode(PKCSDerObject.java:251)
at com.ibm.security.pkcs12.CertBag.<init>(CertBag.java:76)
at com.ibm.security.pkcs12.BasicPFX.getCertificates(BasicPFX.java:1422)
at com.ibm.security.pkcs12.PFX.getCertificates(PFX.java:549)
at com.ibm.crypto.provider.PKCS12KeyStore.engineLoad(Unknown Source)
at java.security.KeyStore.load(KeyStore.java:414)
at sfmsbr.bankapi.UMAC.getSingedData(UMAC.java:137)
at sfmsbr.bankapi.SignedDataImpl.getSingedData(SignedDataImpl.java:42)
at com.cs.sfms.SFMSMessageSender.run(SFMSMessageSender.java:226)
at java.lang.Thread.run(Thread.java:736)
18:10:05 10-Feb-2012 AFTER JAVA Execution
Please share your valuable inputs to resolve this
Regards,
Haris

The Best Answer

Advertisement
java version
java version "1.6.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pap32devifx-20110211b (SR12 FP3 +IZ94331))
IBM J9 VM (build 2.3, J2RE 1.6.0 IBM J9 2.3 AIX ppc-32 j9vmap3223ifx-20101130 (JIT enabled)
J9VM - 20101129_69669_bHdSMr
JIT - 20100623_16197ifx1_r8
GC - 20100211_AA)
JCL - 20110208
Regards
Haris
Edited by: user12848704 on Feb 10, 2012 3:27 AM