Skip to Main Content

Java Card

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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

error: java.security.ProviderException: Initialization failed

688396Jul 23 2008
H� people,

I have taken an error while I am debugging my code? It may be caused from config file. My aim is to connect and enter p�n and then store my external cert�f�cate to smart card which has not support for java card. I am using ACR38 Smart card reader and compliant smart card....

Hata: java.security.ProviderException: Initialization failed

************************************************************************
# pkcs11.config
name = Safesign
library = C:\WINDOWS\system32\siecap11.dll
slot=1
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_SENSITIVE=true
}

attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_TOKEN=true
}

attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_SIGN = true
}
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_PRIVATE=true
}
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_MODIFIABLE=true
}

attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_DERIVE=false
}

attributes(*,CKO_CERTIFICATE,*) = {
CKA_TRUSTED=true
}
attributes(*,CKO_CERTIFICATE,*) = {
CKA_TOKEN=true
}

attributes(*,CKO_CERTIFICATE,*) = {
CKA_MODIFIABLE=true
}

attributes(*,CKO_CERTIFICATE,*) = {
CKA_PRIVATE=true
}
****************************************************

My java program is that :

package test;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.sql.*;
import java.text.*;
import java.math.*;
import java.security.*;
import java.security.cert.*;
import java.security.interfaces.*;
import javax.crypto.interfaces.*;
import javax.net.ssl.*;
import javax.crypto.*;
import javax.crypto.spec.DESKeySpec;
import java.security.KeyStore.*;

public class Main
{

private String configName = "C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\lib\\security\\pkcs11.config";

private KeyStore ks=null;

public Main() {
}

public void loadID(String id)
{
try
{
ks.setEntry("id",new ID(id),new ProtectionParameterDummy());
}
catch(KeyStoreException e)
{
System.err.println("Failed to load ID to keystore");
}
}//loadID

public String retrieveID()
{
KeyStore.Entry entry=null;

try
{
entry=ks.getEntry("id",new ProtectionParameterDummy());
}
catch(NoSuchAlgorithmException e)
{

}
catch(UnrecoverableEntryException e)
{
System.err.println("Failed to retrieve ID to keystore");
}
catch(KeyStoreException e)
{
System.err.println("Failed to retrieve ID to keystore");
}

if (entry==null) {
return "noID";
}
else {
return ((ID)entry).getID();
}
}//loadID



public void login(String sPin) throws NoSuchProviderException, InvalidKeyException,
NoSuchPaddingException, InvalidAlgorithmParameterException
{
Provider p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);

try
{
char pin[] = sPin.toCharArray();
ks = KeyStore.getInstance("pkcs11");
ks.load(null,pin);
}
catch(KeyStoreException e1)
{
System.out.println("error 1"+e1);
}
catch(NoSuchAlgorithmException e2)
{
System.out.println("Error 2"+e2);
}
catch(CertificateException e3)
{
System.out.println("error 3"+e3);
}
catch(IOException e4)
{
System.out.println("error 4"+e4);
}
}//loginToken


private class ID implements KeyStore.Entry
{
String id_="";

ID(String id)
{
id_=id;
}

public String getID()
{
return id_;
}
}//ID



private class ProtectionParameterDummy implements KeyStore.ProtectionParameter
{

}//ProtectionParameterDummy



public static void main (String args[]) throws Exception
{
try
{
Main tl = new Main();
tl.login("PIN");
tl.loadID("9876");
//System.out.println("id: "+tl.retrieveID());
}
catch(Exception e)
{
System.out.println("Hata: " + e.toString());
e.printStackTrace();
}
}//main

}


Error is taken from this command....

Provider p = new sun.security.pkcs11.SunPKCS11(configName);

Comments

Paulzip

select id, category, name from where category like '%'||&category||'%'

jaramill

palkodi wrote:

create table ter (ID number, category varchar2(250 byte), name varchar2(250 byte) );

insert into ter values (1, 'amd-visual theraphy','john');

insert into ter values (1, 'amd-visual theraphy','mike');

insert into ter values (2, 'amd-autmatic theraphy','mike');

insert into ter values (3, 'amd-autmatic theraphy','drane');

insert into ter values (3, 'cmd autmatic theraphy', 'traverse');

Thanks for providing your ddl and dml statements (always make sure to provide your database version in the future.

palkodi wrote:

so if i select this

select id, category, name from where category like '%visual%'

select id, category, name from where category like '%autmatic %' i get the result

but if i want to pass a parameter how to obtain that

select id, category, name from where category like '%visual%' = &catogeory or category like '%autmatic %' =&category (wrong method but want similar like this)

If i enter &category = visual then i need to get this result select id, category, name from where category like '%visual%'

If i enter &category = autmatic then i need to get this result select id, category, name from where category like '%autmatic %'

so what should be done?

You say the first two select statements return the result you DO want.

So you want to pass a parameter?  Just use the ampersand sign (&) to make it a substitution variable (needed in SQL* Plus)

See my formatted version of your code and my query

CODE

drop table ter cascade constraints purge;

create table ter

(

id       number

,category varchar2(250 byte)

,name     varchar2(250 byte)

);

insert into ter values (1, 'amd-visual theraphy','john');

insert into ter values (1, 'amd-visual theraphy','mike');

insert into ter values (2, 'amd-autmatic theraphy','mike');

insert into ter values (3, 'amd-autmatic theraphy','drane');

insert into ter values (3, 'cmd autmatic theraphy', 'traverse');

commit;

OUTPUT

Time Start: 08-22-2018 12:54:47

Table dropped.

Table created.

1 row created.

1 row created.

1 row created.

1 row created.

1 row created.

Commit complete.

Time End: 08-22-2018 12:54:48

Elapsed Time for Script Execution: 474 msecs

SQL

select id

      ,category

      ,name

  from ter

where category like '%&visual%';

OUTPUT

Time Start: 08-22-2018 12:58:30

old: select id

      ,category

      ,name

  from ter

where category like '%&visual%'

new: select id

      ,category

      ,name

  from ter

where category like '%visual%'

   ID CATEGORY                       NAME     

----- ------------------------------ ----------

    1 amd-visual theraphy            john     

    1 amd-visual theraphy            mike     

2 rows selected.

Time End: 08-22-2018 12:58:31

Elapsed Time for Script Execution: 1 sec

SQL

column id format 9999

column category format a30

column name format a10

select id

      ,category

      ,name

  from ter

where category like '%&autmatic %';

OUTPUT

Time Start: 08-22-2018 13:00:00

old: select id

      ,category

      ,name

  from ter

where category like '%&autmatic %'

new: select id

      ,category

      ,name

  from ter

where category like '%autmatic %'

   ID CATEGORY                       NAME     

----- ------------------------------ ----------

    2 amd-autmatic theraphy          mike     

    3 amd-autmatic theraphy          drane    

    3 cmd autmatic theraphy          traverse 

3 rows selected.

Time End: 08-22-2018 13:00:03

Elapsed Time for Script Execution: 2 secs

Frank Kulash
Answer

Hi,

Paulzip wrote:

select id, category, name from where category like '%'||&category||'%'

If &category = visual, then that will expect a column named VISUAL.

If I understand OP's question correctly, you want &category to be inside single-quotes, like this:

select  id, category, name 
from    ter
where   category  like '%&category%';
Marked as Answer by palkodi · Sep 27 2020
Paulzip

Frank Kulash wrote:

Hi,

Paulzip wrote:

select id, category, name from where category like '%'||&category||'%'

If &category = visual, then that will expect a column named VISUAL.

If I understand OP's question correctly, you want &category to be inside single-quotes, like this:

select id, category, name
from ter
where category like '%&category%';

You could well be correct there, Frank. It seems I've interpreted it differently / incorrectly.

mathguy

Paulzip wrote:

select id, category, name from where category like '%'||&category||'%'

In this solution, the user would have to enter    'visual'     (including the single quotes) when prompted for &category; otherwise the query will interpret VISUAL as an identifier and throw an error.

You could rewrite this as  '%'||'&category'||'%'   This is exactly what Frank wrote, except that he wrote it much more simply.

jaramill

Which is the same thing I did in my reply.  I just put the ampersand inside the quotes and when you run it, it looks for the value at the prompt.

mathguy

Not exactly (unless I am missing something). In your Reply you used the parameter values as the name of the substitution variable (as in, '%&visual&' and '%&autmatic %', respectively); the OP requires a single variable name, which he showed as &category. You show two different SQL statements for the two input strings; there should only be one SQL statement.

jaramill

mathguy wrote:

Not exactly (unless I am missing something). In your Reply you used the parameter values as the name of the substitution variable (as in, '%&visual&' and '%&autmatic %', respectively); the OP requires a single variable name, which he showed as &category. You show two different SQL statements for the two input strings; there should only be one SQL statement.

Ah gotcha.  His original post I must have misread as it was a clear as mud

1 - 8
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 20 2008
Added on Jul 23 2008
0 comments
1,065 views