Skip to Main Content

Java Security

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!

%1 is not a valid Win32 application

865052Jun 22 2011 — edited Jun 22 2011
Hello,

I'm trying to compile and run a tutorial using PKCS11 for tokens. Here's the code I'm using
import iaik.pkcs.pkcs11.Module;
import iaik.pkcs.pkcs11.Slot;
import iaik.pkcs.pkcs11.Token;
import iaik.pkcs.pkcs11.TokenException;
import iaik.pkcs.pkcs11.TokenInfo;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 ################################################################################
 ## Special License Rights - Contract #
 ## WARNING: Do not use, modify or deliver without written permission
 ## from Harris Corporation
 ################################################################################
 /*******************************************************************************
 * FILE: SmartCardTutorial.java
 *
 * Copyright (C) 2011 Harris Corporation. All rights reserved.
 *
 * CLASSIFICATION: Unclassified
 *
 *******************************************************************************/

/**
 * 
 * @author <a href="mailto:kjones34@harris.com">kjones34</a>
 */
public class SmartCardTutorial
{
   private Module pkcs11Module;
   public static String DLL = "C:\\Windows\\system32\\acpkcs211.dll";

   public SmartCardTutorial(String librarayPath)
   {
      try
      {
         pkcs11Module = Module.getInstance(librarayPath);
         pkcs11Module.initialize(null);
      }
      catch (IOException ex)
      {
         Logger.getLogger(SmartCardTutorial.class.getName()).log(Level.SEVERE,
                                                                 null,
                                                                 ex);
      }
      catch (TokenException ex)
      {
         Logger.getLogger(SmartCardTutorial.class.getName()).log(Level.SEVERE,
                                                                 null,
                                                                 ex);
      }
   }

   public Slot[] getTokenSlots()
      throws TokenException
   {
      return pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
   }

   public void printTokenInfos()
      throws TokenException
   {
      Slot[] slots = getTokenSlots();
      if (slots.length == 0)
      { // No tokens connected
         System.out.println("Sorry, Couldn't find any token");
      }
      else
      {
         // Let's get the first slot
         Slot selectedSlot = slots[0];
         // Let's get the connected token
         Token token = selectedSlot.getToken();
         // Get the token infos
         TokenInfo tokenInfo = token.getTokenInfo();
         System.out.println("Token : " + tokenInfo.getLabel());
         System.out.println("Vendor : " + tokenInfo.getManufacturerID());
         System.out.println("Serial Number : " + tokenInfo.getSerialNumber());
      }
   }

   /**
    * @param args
    */
   public static void main(String[] args)
   {
      SmartCardTutorial sct = new SmartCardTutorial(DLL);
      try
      {
         sct.printTokenInfos();
      }
      catch (TokenException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

   }

}
and here's the error I get:
Jun 22, 2011 3:35:21 PM SmartCardTutorial <init>
SEVERE: null
java.io.IOException: %1 is not a valid Win32 application.
C:\Windows\system32\acpkcs211.dll
	at iaik.pkcs.pkcs11.wrapper.PKCS11Implementation.connect(Native Method)
	at iaik.pkcs.pkcs11.wrapper.PKCS11Implementation.<init>(PKCS11Implementation.java:166)
	at iaik.pkcs.pkcs11.wrapper.PKCS11Connector.connectToPKCS11Module(PKCS11Connector.java:75)
	at iaik.pkcs.pkcs11.Module.getInstance(Module.java:202)
	at SmartCardTutorial.<init>(SmartCardTutorial.java:39)
	at SmartCardTutorial.main(SmartCardTutorial.java:89)
Exception in thread "main" java.lang.NullPointerException
	at SmartCardTutorial.getTokenSlots(SmartCardTutorial.java:59)
	at SmartCardTutorial.printTokenInfos(SmartCardTutorial.java:65)
	at SmartCardTutorial.main(SmartCardTutorial.java:92)
I'm not familiar with this error and I'm not sure where to start looking to fix the problem.
Has anyone encountered this before?
This post has been answered by safarmer on Jun 22 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2011
Added on Jun 22 2011
7 comments
2,726 views