コード例 #1
0
  public static KeyStore createKeyStore() throws Exception {
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(null, null);

    X500PrivateCredential rootCredential = createRootCredential();
    X500PrivateCredential interCredential =
        createIntermediateCredential(
            rootCredential.getPrivateKey(), rootCredential.getCertificate());
    X500PrivateCredential endCredential =
        createEndEntityCredential(
            interCredential.getPrivateKey(), interCredential.getCertificate());

    keyStore.setCertificateEntry(rootCredential.getAlias(), rootCredential.getCertificate());
    keyStore.setKeyEntry(
        endCredential.getAlias(),
        endCredential.getPrivateKey(),
        ConfigurationClass.PRIVATE_KEY_PASSWORD.toCharArray(),
        new Certificate[] {
          endCredential.getCertificate(),
          interCredential.getCertificate(),
          rootCredential.getCertificate()
        });

    keyStore.store(
        new FileOutputStream(ConfigurationClass.JAVA_KEY_STORE_PATH),
        ConfigurationClass.KEY_STORE_PASSWORD.toCharArray());
    return keyStore;
  }
コード例 #2
0
 //	public static final char[] KEY_STORE_PASSWORD = "******".toCharArray();
 //	public static final long VALIDITY_PERIOD = 365 * 24 * 60 * 60 * 1000;
 //	public static final char[] KEY_PASSWORD = "******".toCharArray();
 //	public static String ROOT_ALIAS = "root";
 //	public static String INTERMEDIATE_ALIAS = "intermediate";
 //	public static String END_ENTITY_ALIAS = "end";
 //	public static final String KEY_STORE_PATH = ConfigurationClass.JAVA_KEY_STORE_PATH;
 //	public static final String SIGNED_DATA_PATH = "d:\\pkcs7\\SIGNED_DATA.sign";
 //	public static final String SIGNED_ENCRYPTED_DATA_PATH = "d:\\pkcs7\\SIGNED_ENC_DATA.sign";
 //	public static final String PLAIN_TEXT_FILE_PATH = "d:\\pkcs7\\PlainText.txt";
 //	public static final String RESULT_DATA_FILE_PATH = "d:\\pkcs7\\ResultData.txt";
 //	public static final String DECRYPTED_DATA_FILE_PATH = "d:\\pkcs7\\DECRYPTED_DATA.txt";
 public static KeyStore loadKeyStore() throws Exception {
   KeyStore keyStore = KeyStore.getInstance("JKS");
   InputStream is = new FileInputStream(new File(ConfigurationClass.JAVA_KEY_STORE_PATH));
   keyStore.load(is, ConfigurationClass.KEY_STORE_PASSWORD.toCharArray());
   is.close();
   return keyStore;
 }