如何验证我自己的提供商(仅用于测试目的)

时间:2010-04-05 13:03:20

标签: java jce

现在,我写了一个新的提供程序(ESMJCE提供程序),我还编写了一个简单的应用程序来测试它,但是我有一些例外

java.lang.SecurityException: JCE cannot authenticate the provider ESMJCE
at javax.crypto.Cipher.getInstance(DashoA13*..)
at javax.crypto.Cipher.getInstance(DashoA13*..)
at testprovider.main(testprovider.java:27)
Caused by: java.util.jar.JarException: Cannot parse file:/C:/Program%20Files/Java/jre1.6.0_02/lib/ext/abc.jar
at javax.crypto.SunJCE_c.a(DashoA13*..)
at javax.crypto.SunJCE_b.b(DashoA13*..)
at javax.crypto.SunJCE_b.a(DashoA13*..)
... 3 more

这是我的源代码

import java.security.Provider;
import java.security.Security;
import javax.crypto.Cipher;
import esm.jce.provider.ESMProvider;

public class testprovider {

/
@param args
/
public static void main(String[] args) {
  // TODO Auto-generated method stub
  ESMProvider esmprovider = new esm.jce.provider.ESMProvider();

  Security.insertProviderAt(esmprovider,2);

  Provider[] temp = Security.getProviders();
  for (int i= 0; i<temp.length; i++){
    System.out.println("Providers: " temp[i].getName());
  }
  try{
    Cipher cipher = Cipher.getInstance("DES", "ESMJCE");
    System.out.println("Cipher: " cipher);
    int blockSize= cipher.getBlockSize();
    System.out.println("blockSize= " + blockSize);
  }catch (Exception e){
    e.printStackTrace();
  } 
}
}

请帮我解决这个问题

由于

2 个答案:

答案 0 :(得分:1)

实际上,您可以绕过Sun-rooted证书要求,并可以自己签署提供商:Java HotSpot Cryptographic Provider signature verification issue。当然,请先查看此处:http://download.oracle.com/javase/6/docs/technotes/guides/security/crypto/HowToImplAProvider.html#Step61

答案 1 :(得分:0)

除非您编写自己的JVM,否则无法对其进行身份验证。否则请求JVM提供程序(Oracle)签署您的Jars。