当前位置: 首页>>代码示例>>Java>>正文


Java KeyInfo类代码示例

本文整理汇总了Java中javax.xml.crypto.dsig.keyinfo.KeyInfo的典型用法代码示例。如果您正苦于以下问题:Java KeyInfo类的具体用法?Java KeyInfo怎么用?Java KeyInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyInfo类属于javax.xml.crypto.dsig.keyinfo包,在下文中一共展示了KeyInfo类的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: select_wrong_structType

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Test()
public void select_wrong_structType() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    KeyName struct = mock(KeyName.class);
    list.add(struct);
    doReturn(list).when(keyinfo).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("No X509Data element found."));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:X509KeySelectorTest.java

示例3: select_x509Data_empty

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Test()
public void select_x509Data_empty() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    X509Data x509Data = mock(X509Data.class);
    list.add(x509Data);
    doReturn(list).when(keyinfo).getContent();
    doReturn(new ArrayList<Object>()).when(x509Data).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("No X509Data element found."));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:X509KeySelectorTest.java

示例4: select_x509Data_noCertificate

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Test()
public void select_x509Data_noCertificate() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    X509Data x509Data = mock(X509Data.class);
    list.add(x509Data);
    doReturn(list).when(keyinfo).getContent();
    ArrayList<Object> x509DataContent = new ArrayList<Object>();
    x509DataContent.add(new String());
    doReturn(x509DataContent).when(x509Data).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("No X509Data element found."));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:X509KeySelectorTest.java

示例5: select_publicKey_exception

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Test()
public void select_publicKey_exception() throws Exception {
    // given
    selector = spy(new X509KeySelector(keystore));
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    X509Data x509Data = mock(X509Data.class);
    list.add(x509Data);
    doReturn(list).when(keyinfo).getContent();
    ArrayList<Object> x509DataContent = new ArrayList<Object>();
    x509DataContent.add(mock(X509Certificate.class));
    doReturn(x509DataContent).when(x509Data).getContent();
    doThrow(new KeyStoreException("key exception")).when(selector)
            .getPublicKeyFromKeystore(any(X509Certificate.class),
                    any(SignatureMethod.class));

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getCause().getMessage().contains("key exception"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:X509KeySelectorTest.java

示例6: select_wrong_structType

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Test()
public void select_wrong_structType() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    KeyName struct = mock(KeyName.class);
    list.add(struct);
    doReturn(list).when(keyinfo).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains(
                "No RSA/DSA KeyValue element found"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:KeyValueKeySelectorTest.java

示例7: select_publicKey_exception

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Test()
public void select_publicKey_exception() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    KeyValue struct = mock(KeyValue.class);
    list.add(struct);
    doReturn(list).when(keyinfo).getContent();
    doThrow(new KeyException("test")).when(struct).getPublicKey();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getCause().getMessage().contains("test"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:KeyValueKeySelectorTest.java

示例8: equals

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof KeyInfo)) {
        return false;
    }
    KeyInfo oki = (KeyInfo)o;

    boolean idsEqual = (id == null ? oki.getId() == null
                                   : id.equals(oki.getId()));

    return (keyInfoTypes.equals(oki.getContent()) && idsEqual);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:DOMKeyInfo.java

示例9: DOMXMLSignature

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
/**
 * Creates a <code>DOMXMLSignature</code> from the specified components.
 *
 * @param si the <code>SignedInfo</code>
 * @param ki the <code>KeyInfo</code>, or <code>null</code> if not specified
 * @param objs a list of <code>XMLObject</code>s or <code>null</code>
 *  if not specified. The list is copied to protect against subsequent
 *  modification.
 * @param id an optional id (specify <code>null</code> to omit)
 * @param signatureValueId an optional id (specify <code>null</code> to
 *  omit)
 * @throws NullPointerException if <code>si</code> is <code>null</code>
 */
public DOMXMLSignature(SignedInfo si, KeyInfo ki,
                       List<? extends XMLObject> objs,
                       String id, String signatureValueId)
{
    if (si == null) {
        throw new NullPointerException("signedInfo cannot be null");
    }
    this.si = si;
    this.id = id;
    this.sv = new DOMSignatureValue(signatureValueId);
    if (objs == null) {
        this.objects = Collections.emptyList();
    } else {
        this.objects =
            Collections.unmodifiableList(new ArrayList<XMLObject>(objs));
        for (int i = 0, size = this.objects.size(); i < size; i++) {
            if (!(this.objects.get(i) instanceof XMLObject)) {
                throw new ClassCastException
                    ("objs["+i+"] is not an XMLObject");
            }
        }
    }
    this.ki = ki;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:DOMXMLSignature.java

示例10: DOMXMLSignature

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
/**
 * Creates a <code>DOMXMLSignature</code> from the specified components.
 *
 * @param si the <code>SignedInfo</code>
 * @param ki the <code>KeyInfo</code>, or <code>null</code> if not specified
 * @param objs a list of <code>XMLObject</code>s or <code>null</code>
 *  if not specified. The list is copied to protect against subsequent
 *  modification.
 * @param id an optional id (specify <code>null</code> to omit)
 * @param signatureValueId an optional id (specify <code>null</code> to
 *  omit)
 * @throws NullPointerException if <code>si</code> is <code>null</code>
 */
public DOMXMLSignature(SignedInfo si, KeyInfo ki,
                       List<? extends XMLObject> objs,
                       String id, String signatureValueId)
{
    if (si == null) {
        throw new NullPointerException("signedInfo cannot be null");
    }
    this.si = si;
    this.id = id;
    this.sv = new DOMSignatureValue(signatureValueId);
    List<XMLObject> tempList =
        Collections.checkedList(new ArrayList<XMLObject>(),
                                XMLObject.class);
    if (objs != null) {
        tempList.addAll(objs);
    }
    this.objects = Collections.unmodifiableList(tempList);
    this.ki = ki;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:DOMXMLSignature.java

示例11: marshalInternal

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
private static void marshalInternal(XmlWriter xwriter, KeyInfo ki,
    String dsPrefix, XMLCryptoContext context, boolean declareNamespace) throws MarshalException {

    xwriter.writeStartElement(dsPrefix, "KeyInfo", XMLSignature.XMLNS);
    if (declareNamespace) {
        xwriter.writeNamespace(dsPrefix, XMLSignature.XMLNS);
    }

    xwriter.writeIdAttribute("", "", "Id", ki.getId());
    // create and append KeyInfoType elements
    List<XMLStructure> keyInfoTypes = getContent(ki);
    for (XMLStructure kiType : keyInfoTypes) {
        xwriter.marshalStructure(kiType, dsPrefix, context);
    }

    xwriter.writeEndElement(); // "KeyInfo"
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:18,代码来源:DOMKeyInfo.java

示例12: equals

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof KeyInfo)) {
        return false;
    }
    KeyInfo oki = (KeyInfo)o;

    boolean idsEqual = id == null ? oki.getId() == null
                                   : id.equals(oki.getId());

    return keyInfoTypes.equals(oki.getContent()) && idsEqual;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:DOMKeyInfo.java

示例13: 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

示例14: 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

示例15: getKeyAccessor

import javax.xml.crypto.dsig.keyinfo.KeyInfo; //导入依赖的package包/类
static KeyAccessor getKeyAccessor() {
    KeyAccessor accessor = new KeyAccessor() {

        @Override
        public KeySelector getKeySelector(Message message) throws Exception {
            return KeySelector.singletonKeySelector(getKeyFromKeystore());
        }

        @Override
        public KeyInfo getKeyInfo(Message mess, Node messageBody,
                                  KeyInfoFactory keyInfoFactory) throws Exception {
            return null;
        }
    };
    return accessor;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:ECDSASignatureTest.java


注:本文中的javax.xml.crypto.dsig.keyinfo.KeyInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。