code: @Override
      public PrivateKey getPrivateKeyFromKeyStore(String keyStoreName) throws KeyStoreException, CertificateException {
          try {
              WSKeyStore wsKS = ksMgr.getKeyStore(keyStoreName);
              if (wsKS == null) {
                  throw new KeyStoreException("The WSKeyStore [" + keyStoreName + "] is not present in the configuration");
              }
  
              String keyAlias = null;
              Enumeration<String> aliases = wsKS.aliases();
              if (aliases != null) {
                  while (aliases.hasMoreElements()) {
                      String alias = aliases.nextElement();
                      if (wsKS.isKeyEntry(alias)) {
                          if (keyAlias != null)
                              return null;
                          else
                              keyAlias = alias;
                      }
                  }
              }
  
              if (keyAlias != null) {
                  Key key = wsKS.getKey(keyAlias, null);
                  if (key instanceof PrivateKey) {
                      return (PrivateKey) key;
                  } else {
                      throw new CertificateException("The alias [" + keyAlias + "] is not an instance of PrivateKey");
                  }
              } else {
                  return null;
              }
          } catch (CertificateException e) {
              throw e;
          } catch (KeyStoreException e) {
              throw e;
          } catch (Exception e) {
              throw new KeyStoreException("Unexpected error while loading the private key for alias from keystore: " + keyStoreName, e);
          }
      }
docs: {@inheritDoc}