*
Adds the keyStore to the keyStoreMap.

@param keyStoreName
@param ks
@throws Exception
*
767959
public void addKeyStoreToMap(String keyStoreName, WSKeyStore ks) throws Exception {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "addKeyStoreToMap: " + keyStoreName + ", ks=" + ks);

        if (keyStoreMap.containsKey(keyStoreName))
            keyStoreMap.remove(keyStoreName);
        keyStoreMap.put(keyStoreName, ks);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "addKeyStoreToMap");
    }
1001275
public synchronized void
addTrustedKey(DNSKEYRecord key) {
	Name name = key.getName();
	List list = (List) trustedKeys.get(name);
	if (list == null)
		trustedKeys.put(name, list = new LinkedList());
	list.add(key);
}
1060977
public static InputStream openKeyStore(String fileName) throws MalformedURLException, IOException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "openKeyStore: " + fileName);

        URL urlFile = null;

        // Check if the filename exists as a File.
        File kfile = new File(fileName);

        if (kfile.exists() && kfile.length() == 0) {
            throw new IOException("Keystore file exists, but is empty: " + fileName);
        } else if (!kfile.exists()) {
            urlFile = new URL(fileName);
        } else {
            // kfile exists
            urlFile = new URL("file:" + kfile.getCanonicalPath());
        }

        // Finally open the file.
        InputStream fis = urlFile.openStream();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "openKeyStore: " + (null != fis));
        return fis;
    }
695879
public void clearJavaKeyStoresFromKeyStoreMap() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "clearJavaKeyStoresFromKeyStoreMap");
        synchronized (keyStoreMap) {
            for (Entry<String, WSKeyStore> entry : keyStoreMap.entrySet()) {
                WSKeyStore ws = entry.getValue();

                if (ws != null)
                    ws.clearJavaKeyStore();
            }
        }
    }
393656
private void loadKeystore() {
		String keypath = this.getProperty(KEY_PATH_PROPERTY_KEY);
		String keyEntryName = this.getProperty(ENTRY_NAME_PROPERTY_KEY);
		String keyStorePassword = this
				.getProperty(KEYSTORE_PASSWORD_PROPERTY_KEY);

		loadKeystore(keypath, keyStorePassword, keyEntryName);

	}
817964
@NotNull
    public static String getSku(@NotNull final String appStoreName, @NotNull String storeSku) {
        return SkuManager.getInstance().getSku(appStoreName, storeSku);
    }
59650
public final String encodeKeyStore(KeyStore keyStore, char[] password) {
        logger.entry();
        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            keyStore.store(out, password);
            out.flush();
            byte[] bytes = out.toByteArray();
            String encodedKeyStore = Base64Utils.encode(bytes);
            logger.exit();
            return encodedKeyStore;
        } catch (IOException | KeyStoreException | NoSuchAlgorithmException | CertificateException e) {
            RuntimeException exception = new RuntimeException("An unexpected exception occurred while attempting to encode a keystore.", e);
            logger.error(exception.toString());
            throw exception;
        }
    }
44749
private void readKeyStore(Configuration conf) throws IOException, FormatNotUnderstoodException {
	if ((this.hocr.getCryptKeystoreFile()!=null) && (!"".equals(this.hocr.getCryptKeystoreFile()))) {
		LOG.info("Using keystore to obtain credentials instead of passwords");
		HadoopKeyStoreManager hksm = new HadoopKeyStoreManager(conf);
		try {
			hksm.openKeyStore(new Path(this.hocr.getCryptKeystoreFile()), this.hocr.getCryptKeystoreType(), this.hocr.getCryptKeystorePassword());
			String pw="";
			if ((this.hocr.getCryptKeystoreAlias()!=null) && (!"".equals(this.hocr.getCryptKeystoreAlias()))) {
				pw=hksm.getPassword(this.hocr.getCryptKeystoreAlias(), this.hocr.getCryptKeystorePassword());
			} else {
				pw=hksm.getPassword(this.hocr.getFileName(), this.hocr.getCryptKeystorePassword());
			}
			this.hocr.setPassword(pw);
		} catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IllegalArgumentException | UnrecoverableEntryException | InvalidKeySpecException e) {
			LOG.error("Cannopt read keystore. Exception: ",e);
			throw new FormatNotUnderstoodException("Cannot read keystore to obtain credentials to access encrypted documents "+e);
		}
		
	}
}
491792
public void setKeyStore(String keyStore, String keyPass) 
    {
        setKeyStore(keyStore, keyPass, null, null);
    }
700001
public void initializeKeyStore(boolean reinitialize) throws Exception {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "initializeKeyStore");

        try {
            String initAtStartup = getProperty(Constants.SSLPROP_KEY_STORE_INITIALIZE_AT_STARTUP);
            boolean createIfMissing = LibertyConstants.DEFAULT_KEYSTORE_REF_ID.equals(getProperty("id"));

            if (Boolean.parseBoolean(initAtStartup) || reinitialize) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "Initializing keystore at startup.");
                getKeyStore(reinitialize, createIfMissing);
            }
        } catch (Exception e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "Exception initializing KeyStore; " + e);
            throw e;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "initializeKeyStore");
    }
1195792
public static void validate(byte[] cert, String pass) throws Exception {

        try {
            KeyStore keyStore = KeyStore.getInstance(ALGORITHM);
            keyStore.load(new ByteArrayInputStream(cert), pass.toCharArray());
        } catch (Exception e) {
            throw new Exception("Certificate is not valid!", e);
        }
    }
1304857
public static KeyStore loadCacertsKeyStore(String provider) {
        File file = new File(System.getProperty("java.home"), "lib");
        file = new File(file, "security");
        file = new File(file, "cacerts");
        FileInputStream fin = null;
        try {
            fin = new FileInputStream(file);
            KeyStore k;
            if (provider == null)
                k = KeyStore.getInstance("JKS");
            else
                k = KeyStore.getInstance("JKS", provider);
            k.load(fin, null);
            return k;
        }
        catch (Exception e) {
            throw new ExceptionConverter(e);
        }
        finally {
            try{if (fin != null) {fin.close();}}catch(Exception ex){}
        }
    }
420829
@Override
    public boolean delete(K key) throws Exception {
        if(key == null) {
            throw new NullPointerException("key");
        }
        
        return _store.delete(_keySerializer.serialize(key));
    }
459032
public static void saveKeyStore(File targetStoreFile, KeyStore store, String password) {
        File folder = targetStoreFile.getAbsoluteFile().getParentFile();
        if (!folder.exists()) {
            folder.mkdirs();
        }
        File tmpFile = new File(folder, Long.toHexString(System.currentTimeMillis()) + ".tmp");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(tmpFile);
            store.store(fos, password.toCharArray());
            fos.flush();
            fos.close();
            if (targetStoreFile.exists()) {
                targetStoreFile.delete();
            }
            tmpFile.renameTo(targetStoreFile);
        } catch (IOException e) {
            String message = e.getMessage().toLowerCase();
            if (message.contains("illegal key size")) {
                throw new RuntimeException("Illegal Key Size! You might consider installing the JCE Unlimited Strength Jurisdiction Policy files for your JVM.");
            } else {
                throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }

            if (tmpFile.exists()) {
                tmpFile.delete();
            }
        }
    }
1898
private KeyStore createKeyStore(String fileName, String password)  {
        File file = new File(fileName);
        KeyStore keyStore = null;
        try {
            keyStore = KeyStore.getInstance("JCEKS");
            if (file.exists()) {
                keyStore.load(new FileInputStream(file), password.toCharArray());
            } else {
                keyStore.load(null, null);
                keyStore.store(new FileOutputStream(fileName), password.toCharArray());
            }
        } catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException e) {
            logger.error("Unable to create key store", e);
        }

        return keyStore;
    }
907921
public synchronized void addSSLPropertiesFromKeyStore(WSKeyStore wsks, SSLConfig sslprops) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "addSSLPropertiesFromKeyStore");

        for (Enumeration<?> e = wsks.propertyNames(); e.hasMoreElements();) {
            String property = (String) e.nextElement();
            String value = wsks.getProperty(property);
            sslprops.setProperty(property, value);
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "addSSLPropertiesFromKeyStore");
    }
474631
public KeyStoreCredentialResolverBuilder addKeyPassword(String name, String password) {
        requireNonNull(name, "name");
        requireNonNull(password, "password");
        checkArgument(!keyPasswords.containsKey(name), "key already exists: %s", name);
        keyPasswords.put(name, password);
        return this;
    }