本文整理汇总了Java中javax.xml.crypto.KeySelector.singletonKeySelector方法的典型用法代码示例。如果您正苦于以下问题:Java KeySelector.singletonKeySelector方法的具体用法?Java KeySelector.singletonKeySelector怎么用?Java KeySelector.singletonKeySelector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.crypto.KeySelector
的用法示例。
在下文中一共展示了KeySelector.singletonKeySelector方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testValidatePublicKey
import javax.xml.crypto.KeySelector; //导入方法依赖的package包/类
@Test
public void testValidatePublicKey () throws Exception
{
final AuthorizationRequest request = makeRequest ();
final Document doc = this.builder.buildFromRequest ( request );
this.signer.sign ( this.kp, doc );
System.out.println ( "Key: " + this.kp.getPrivate () );
final RequestValidator validator1 = new RequestValidator ( KeySelector.singletonKeySelector ( this.kp.getPublic () ) );
final RequestValidator validator2 = new RequestValidator ( new KeyValueKeySelector () );
Assert.assertTrue ( "XML Core Validation (Public Key)", validator1.validate ( doc ).isValid () );
Assert.assertTrue ( "XML Core Validation (KeyValueKeySelector)", validator2.validate ( doc ).isValid () );
}
示例2: getKeyAccessor
import javax.xml.crypto.KeySelector; //导入方法依赖的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;
}
示例3: main
import javax.xml.crypto.KeySelector; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
Document doc = dbf.newDocumentBuilder().parse(new File(SIGNATURE));
NodeList nl = doc.getElementsByTagNameNS(XMLSignature.XMLNS,
"Signature");
if (nl.getLength() == 0) {
throw new RuntimeException("Couldn't find 'Signature' element");
}
Element element = (Element) nl.item(0);
byte[] keyBytes = Base64.getDecoder().decode(validationKey);
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
PublicKey key = kf.generatePublic(spec);
KeySelector ks = KeySelector.singletonKeySelector(key);
DOMValidateContext vc = new DOMValidateContext(ks, element);
// disable secure validation mode
vc.setProperty("org.jcp.xml.dsig.secureValidation", Boolean.FALSE);
// set a dummy dereferencer to be able to get content by references
vc.setURIDereferencer(dereferencer);
XMLSignatureFactory factory = XMLSignatureFactory.getInstance();
XMLSignature signature = factory.unmarshalXMLSignature(vc);
// run validation
signature.validate(vc);
}
示例4: testsetngetKeySelector
import javax.xml.crypto.KeySelector; //导入方法依赖的package包/类
@org.junit.Test
public void testsetngetKeySelector() throws Exception {
defContext.setKeySelector(null);
assertNull(defContext.getKeySelector());
KeySelector ks = KeySelector.singletonKeySelector(KEYS[0]);
defContext.setKeySelector(ks);
assertEquals(defContext.getKeySelector(), ks);
}
示例5: getKeyAccessor
import javax.xml.crypto.KeySelector; //导入方法依赖的package包/类
static KeyAccessor getKeyAccessor(final PrivateKey privateKey) {
KeyAccessor accessor = new KeyAccessor() {
@Override
public KeySelector getKeySelector(Message message) throws Exception {
return KeySelector.singletonKeySelector(privateKey);
}
@Override
public KeyInfo getKeyInfo(Message mess, Node messageBody, KeyInfoFactory keyInfoFactory) throws Exception {
return null;
}
};
return accessor;
}
示例6: getKeyAccessor
import javax.xml.crypto.KeySelector; //导入方法依赖的package包/类
static KeyAccessor getKeyAccessor(final Key key) {
KeyAccessor accessor = new KeyAccessor() {
@Override
public KeySelector getKeySelector(Message message) throws Exception {
return KeySelector.singletonKeySelector(key);
}
@Override
public KeyInfo getKeyInfo(Message mess, Node messageBody, KeyInfoFactory keyInfoFactory) throws Exception {
return null;
}
};
return accessor;
}
示例7: getDsaKeySelector
import javax.xml.crypto.KeySelector; //导入方法依赖的package包/类
public static KeySelector getDsaKeySelector() {
return KeySelector.singletonKeySelector(getKeyPair("DSA", 1024).getPublic());
}
示例8: getRsaKeySelector
import javax.xml.crypto.KeySelector; //导入方法依赖的package包/类
public static KeySelector getRsaKeySelector() {
return KeySelector.singletonKeySelector(rsaPair.getPublic());
}