當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyInfo.getContent方法代碼示例

本文整理匯總了Java中javax.xml.crypto.dsig.keyinfo.KeyInfo.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyInfo.getContent方法的具體用法?Java KeyInfo.getContent怎麽用?Java KeyInfo.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.crypto.dsig.keyinfo.KeyInfo的用法示例。


在下文中一共展示了KeyInfo.getContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
		throws KeySelectorException {

	for (Object o : keyInfo.getContent()) {
		if (o instanceof X509Data) {
			for (Object o2 : ((X509Data) o).getContent()) {
				if (o2 instanceof X509Certificate) {
					final X509Certificate cert = (X509Certificate) o2;
					return new KeySelectorResult() {
						public Key getKey() {
							return cert.getPublicKey();
						}
					};
				}
			}
		}
	}

	return null;
}
 
開發者ID:EixoX,項目名稱:jetfuel,代碼行數:22,代碼來源:X509CertificateKeySelector.java

示例2: testgetContent

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@org.junit.Test
@SuppressWarnings("unchecked")
public void testgetContent() {
    KeyInfo[] infos = new KeyInfo[2];
    infos[0] = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "skeleton");
    infos[1] = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")));
    for (int j = 0; j < infos.length; j++) {
        KeyInfo ki = infos[j];
        List<XMLStructure> li = ki.getContent();
        assertNotNull(ki.getContent());
        Object[] content = li.toArray();
        for (int i = 0; i < content.length; i++) {
            if (!(content[i] instanceof XMLStructure)) {
                fail("KeyInfo element has the wrong type");
            }
        }
    }
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:21,代碼來源:KeyInfoTest.java

示例3: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException {
    for (final Object object : keyInfo.getContent()) {
        final XMLStructure info = (XMLStructure) object;
        if (info instanceof X509Data) {
            final X509Data x509Data = (X509Data) info;
            for (final Object certificado : x509Data.getContent()) {
                if (certificado instanceof X509Certificate) {
                    final X509Certificate x509Certificate = (X509Certificate) certificado;
                    if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) {
                        return new KeySelectorResult() {
                            @Override
                            public Key getKey() {
                                return x509Certificate.getPublicKey();
                            }
                        };
                    }
                }
            }
        }
    }
    throw new KeySelectorException("N\u00e3o foi localizada a chave do certificado.");
}
 
開發者ID:GilbertoMattos,項目名稱:nfce,代碼行數:24,代碼來源:X509KeySelector.java

示例4: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException {
    for (final Object object : keyInfo.getContent()) {
        final XMLStructure info = (XMLStructure) object;
        if (info instanceof X509Data) {
            final X509Data x509Data = (X509Data) info;
            for (final Object certificado : x509Data.getContent()) {
                if (certificado instanceof X509Certificate) {
                    final X509Certificate x509Certificate = (X509Certificate) certificado;
                    if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) {
                        return new KeySelectorResult() {
                            @Override
                            public Key getKey() {
                                return x509Certificate.getPublicKey();
                            }
                        };
                    }
                }
            }
        }
    }
    throw new KeySelectorException("Nao foi localizada a chave do certificado.");
}
 
開發者ID:wmixvideo,項目名稱:nfe,代碼行數:24,代碼來源:X509KeySelector.java

示例5: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException
{
    if ( keyInfo == null )
    {
        throw new KeySelectorException ( "Null KeyInfo object!" );
    }

    final SignatureMethod sm = (SignatureMethod)method;
    final List<?> list = keyInfo.getContent ();

    for ( int i = 0; i < list.size (); i++ )
    {
        final XMLStructure xmlStructure = (XMLStructure)list.get ( i );
        if ( xmlStructure instanceof KeyValue )
        {
            try
            {
                final PublicKey pk = ( (KeyValue)xmlStructure ).getPublicKey ();
                // make sure algorithm is compatible with method
                if ( algEquals ( sm.getAlgorithm (), pk.getAlgorithm () ) )
                {
                    return new SimpleKeySelectorResult ( pk );
                }
            }
            catch ( final KeyException ke )
            {
                throw new KeySelectorException ( ke );
            }

        }
    }
    throw new KeySelectorException ( "No KeyValue element found!" );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:35,代碼來源:KeyValueKeySelector.java

示例6: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException
{
    if ( keyInfo == null )
    {
        throw new KeySelectorException ( "Null KeyInfo object!" );
    }

    final SignatureMethod sm = (SignatureMethod)method;
    final List<?> list = keyInfo.getContent ();

    for ( final Object l : list )
    {
        final XMLStructure xmlStructure = (XMLStructure)l;
        if ( xmlStructure instanceof X509Data )
        {
            for ( final Object o : ( (X509Data)xmlStructure ).getContent () )
            {
                KeySelectorResult result = null;
                if ( o instanceof X509Certificate )
                {
                    result = findPublicKey ( (X509Certificate)o, sm );
                }

                if ( result != null )
                {
                    return result;
                }
            }
        }
    }
    throw new KeySelectorException ( "No KeyValue element found!" );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:34,代碼來源:X509KeySelector.java

示例7: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();
    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof X509Data) {
            X509Data x509Data = (X509Data) xmlStructure;
            @SuppressWarnings("rawtypes")
            List content = x509Data.getContent();
            for (int i = 0; i < content.size(); i++) {
                Object x509Content = content.get(i);
                if (x509Content instanceof X509Certificate) {
                    X509Certificate certificate = (X509Certificate) x509Content;
                    try {
                        return getPublicKeyFromKeystore(certificate,
                                (SignatureMethod) algorithmMethod);
                    } catch (KeyStoreException e) {
                        throw new KeySelectorException(e);
                    }
                }
            }
        }
    }

    throw new KeySelectorException("No X509Data element found.");
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:34,代碼來源:X509KeySelector.java

示例8: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();
    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof KeyValue) {
            PublicKey publicKey = null;
            try {
                publicKey = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            if (algorithmCompatibleWithMethod(
                    algorithmMethod.getAlgorithm(),
                    publicKey.getAlgorithm())) {
                return new SimpleKeySelectorResult(publicKey);
            }
        }
    }

    throw new KeySelectorException("No RSA/DSA KeyValue element found");
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:30,代碼來源:KeyValueKeySelector.java

示例9: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
/**
 * Attempts to find a key that satisfies the specified constraints. it's the
 * first public key contained in X509 certificate that match the authorized
 * signature methods.
 *
 * @param keyInfo KeyInfo of the document
 * @param context Crypto context
 * @param method  Algorithm
 * @param purpose Purpose
 * @return A key that satisfies the constraints
 * @throws KeySelectorException Thrown when no keys are found in the document
 */
@SuppressWarnings("rawtypes")
@Override
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method,
                                XMLCryptoContext context) throws KeySelectorException {

    for (Object o1 : keyInfo.getContent()) {

        XMLStructure info = (XMLStructure) o1;

        if (!(info instanceof X509Data)) {
            continue;
        }

        X509Data x509Data = (X509Data) info;

        for (Object o : x509Data.getContent()) {

            if (!(o instanceof X509Certificate)) {
                continue;
            }

            final PublicKey publicKey = ((X509Certificate) o).getPublicKey();

            return () -> publicKey;
        }
    }

    throw new KeySelectorException("No key found!");
}
 
開發者ID:identio,項目名稱:identio-saml,代碼行數:42,代碼來源:X509KeySelector.java

示例10: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
    throws KeySelectorException {
    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    SignatureMethod sm = (SignatureMethod) method;
    @SuppressWarnings("rawtypes")
    List list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKeySelectorResult(pk);
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:28,代碼來源:XmlSignatureTest.java

示例11: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select(final KeyInfo             keyInfo,
                                final KeySelector.Purpose purpose,
                                final AlgorithmMethod     method,
                                final XMLCryptoContext    context)
    throws KeySelectorException 
{
    if (keyInfo == null) {
        throw new KeySelectorException("null KeyInfo");
    }
    List<?> list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        PublicKey pk = null;
        if (xmlStructure instanceof KeyValue) {
            try {
                pk = ((KeyValue)xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
        } else if (xmlStructure instanceof X509Data) {
            List<sun.security.x509.X509CertImpl> certs = ((X509Data)xmlStructure).getContent();
            pk = certs.get(0).getPublicKey();
        } else  {
            log.error(xmlStructure + " not supported");
            continue;
        }
        return new SimpleKeySelectorResult(pk);
    }
    throw new KeySelectorException("No supported KeyValue element found");
}
 
開發者ID:laverca,項目名稱:laverca,代碼行數:33,代碼來源:XmlDsigUtil.java

示例12: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, 
		AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
	if (keyInfo == null)
		throw new KeySelectorException("Null KeyInfo");
	List<?> list = keyInfo.getContent();
	PublicKey pk = null;

	for (int i = 0; i < list.size(); i++) {
		XMLStructure xmlStructure = (XMLStructure) list.get(i);
		if (xmlStructure instanceof KeyValue) {
			try {
				pk = ((KeyValue)xmlStructure).getPublicKey();
			} catch(KeyException ke) {
				throw new KeySelectorException(ke.getMessage());
			}
			break;
		} else if (xmlStructure instanceof X509Data) {
			X509Data x509data = (X509Data)xmlStructure;
			List<?> x509datalist = x509data.getContent();
			for (int j = 0; j < x509datalist.size(); j++) {
				if (x509datalist.get(j) instanceof X509Certificate) {
					X509Certificate cert = (X509Certificate)x509datalist.get(j);
					pk = cert.getPublicKey();
					break;
				}
			}
		}
	}
	if (pk != null) {
		final PublicKey retpk = pk;
		logger.debug("PublicKey from XML=" + pk);
		return new KeySelectorResult() {public Key getKey(){return retpk;}};
	}
	throw new KeySelectorException("Missing KeyValue");
}
 
開發者ID:IRSgov,項目名稱:IDES-Data-Preparation-Java,代碼行數:36,代碼來源:UtilShared.java

示例13: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
@Nonnull
public KeySelectorResult select (@Nonnull final KeyInfo aKeyInfo,
                                 final KeySelector.Purpose aPurpose,
                                 @Nonnull final AlgorithmMethod aMethod,
                                 final XMLCryptoContext aContext) throws KeySelectorException
{
  for (final Object aKeyInfoElement : aKeyInfo.getContent ())
  {
    final XMLStructure aXMLStructure = (XMLStructure) aKeyInfoElement;
    if (aXMLStructure instanceof X509Data)
    {
      // We found a certificate
      final X509Data x509Data = (X509Data) aXMLStructure;
      for (final Object aX509Element : x509Data.getContent ())
      {
        if (aX509Element instanceof X509Certificate)
        {
          final X509Certificate aCert = (X509Certificate) aX509Element;
          final PublicKey aPublicKey = aCert.getPublicKey ();
          // Make sure the algorithm is compatible
          // with the method.
          if (algorithmEquals (aMethod.getAlgorithm (), aPublicKey.getAlgorithm ()))
            return new ConstantKeySelectorResult (aPublicKey);
        }
      }
    }
  }
  throw new KeySelectorException ("No key found!");
}
 
開發者ID:phax,項目名稱:ph-xmldsig,代碼行數:31,代碼來源:X509KeySelector.java

示例14: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
/**
 * KeySelector which retrieves the public key out of the
 * KeyValue element and returns it.
 * NOTE: If the key algorithm doesn't match signature algorithm,
 * then the public key will be ignored.
 */
@Override
public KeySelectorResult select(KeyInfo keyInfo,
                                KeySelector.Purpose purpose,
                                AlgorithmMethod method,
                                XMLCryptoContext context)
    throws KeySelectorException {
    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }
    SignatureMethod sm = (SignatureMethod) method;
    List list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue)xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKeySelectorResult(pk);
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
 
開發者ID:BandwidthOnDemand,項目名稱:nsi-dds,代碼行數:36,代碼來源:KeyValueKeySelector.java

示例15: select

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //導入方法依賴的package包/類
@Override
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }
    SignatureMethod sm = (SignatureMethod) method;
    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();

    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKeySelectorResult(pk);
            }
        }
        if (xmlStructure instanceof X509Data) {
            X509Data xd = (X509Data) xmlStructure;
            @SuppressWarnings("unchecked")
            Iterator<Object> data = xd.getContent().iterator();
            for (; data.hasNext();) {
                Object o = data.next();
                if (o instanceof X509Certificate) {
                    X509Certificate cert = (X509Certificate) o;
                    return new SimpleKeySelectorResult(cert.getPublicKey());
                }
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:40,代碼來源:DefaultSAML2Validator.java


注:本文中的javax.xml.crypto.dsig.keyinfo.KeyInfo.getContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。