public static SignedToken getSignedToken(Principal[] authorities, byte[] token)
			throws NoSuchAlgorithmException, SignatureException, CertificateException {

		PrivateKey privateKey = null;
		X509Certificate[] certificateChain = null;
		try {
			ApplicationKeyManagerFactory keyManagerFactory =
				ApplicationKeyManagerFactory.getInstance();
			for (KeyManager keyManager : keyManagerFactory.getKeyManagers()) {
				if (!(keyManager instanceof X509KeyManager)) {
					continue;
				}
				X509KeyManager x509KeyManager = (X509KeyManager) keyManager;
				String alias = x509KeyManager.chooseClientAlias(new String[] { RSA_TYPE },
					authorities, null);
				if (alias != null) {
					privateKey = x509KeyManager.getPrivateKey(alias);
					certificateChain = x509KeyManager.getCertificateChain(alias);
					break;
				}
			}

			if (privateKey == null || certificateChain == null) {
				CertificateException e =
					new CertificateException("suitable PKI certificate not found");
				e.printStackTrace();
				throw e;
			}

			//
			// See JAVA Examples in a Nutshell (p.358) for use of Signer and
			// IdentityScope classes
			//

			String algorithm = certificateChain[0].getSigAlgName();
			Signature sig = Signature.getInstance(algorithm);
			try {
				sig.initSign(privateKey);
			}
			catch (InvalidKeyException e) {
				throw new CertificateException("suitable PKI certificate not found", e);
			}
			sig.update(token);

			return new SignedToken(token, sig.sign(), certificateChain, algorithm);
		}
		finally {
			if (privateKey != null) {
				// Note: Keystore destroy only supported in Java 1.8
				try {
					privateKey.destroy();
				}
				catch (DestroyFailedException e) {
					// ignore - may not be supported by all keystores
				}
			}
		}
	}
Sign the supplied token byte array using an installed certificate from
one of the specified authorities
@param authorities trusted certificate authorities
@param token token byte array
@return signed token object
@throws NoSuchAlgorithmException algorithym associated within signing certificate not found
@throws SignatureException failed to generate SignedToken
@throws CertificateException error associated with signing certificate
Ghidra/Framework/Generic/src/main/java/ghidra/net/ApplicationKeyManagerUtils.java