起始設定 z/OS SunPKCS11 提供者
z/OS® 起始設定 PKCS#11 提供者的建議方式是使用 SunPKCS11 配置檔。
- 此配置檔名稱可以包含在 $JAVA_HOME/conf/security/java.security 檔中安全提供者清單的 SunPKCS11 提供者行中。
- SunPKCS11 提供者也可以利用配置檔名稱和位置,以程式化方式搭配
provider.configure()方法來起始設定,如下列範例所示。
Provider provider = Security.getProvider("SunPKCS11");
AuthProvider authProv = provider.configure(path);其中 path 是 SunPKCS11 配置檔的路徑和檔名。下列範例程式顯示如何在 $JAVA_HOME/conf/security/java.security 檔中安全提供者清單的 SunPKCS11 行中包含 SunPKCS11 配置檔。
附註: 當 JVM 載入 SunPKCS11 提供者時,會以 PKCS#11 配置檔資訊來建立及起始設定 PKCS#11 階段作業。
public class testPKCS11A {
public static void main(String argv[]) {
Provider p = null;
// Get the SunPKCS11 provider whose PKCS#11
// config file attribute name is PKCS11Config
p = Security.getProvider("SunPKCS11-PKCS11Config");
// Your Java PKCS11 program goes here
}
}下列範例程式顯示如何以程式化方式使用 SunPKCS11 配置檔來起始設定 SunPKCS11 提供者。 在 java.security 檔的 SunPKCS11 行的安全提供者清單中未指定 PKCS#11 配置檔時,這是必要的。
public class testPKCS11B {
public static void main(String argv[]) {
Provider p = null;
AuthProvider authProv = null;
// Get the un-initialized SunPKCS11 provider
p = Security.getProvider("SunPKCS11");
try {
// Create a PKCS#11 session and initialize it
// using the /home/user/pkcs11.cfg PKCS#11
// configuration file
authProv = p.configure("/home/user/pkcs11.cfg");
} catch (Exception ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
// Your Java PKCS11 program goes here
}
}