本文整理汇总了Java中org.apache.ws.security.components.crypto.Crypto类的典型用法代码示例。如果您正苦于以下问题:Java Crypto类的具体用法?Java Crypto怎么用?Java Crypto使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Crypto类属于org.apache.ws.security.components.crypto包,在下文中一共展示了Crypto类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createKeyInfo
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
protected KeyInfoBean createKeyInfo() throws Exception
{
InputStream is = Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties").openStream();
Properties props = new Properties();
try
{
props.load(is);
}
finally
{
is.close();
}
Crypto crypto = CryptoFactory.getInstance(props);
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias("alice");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
KeyInfoBean keyInfo = new KeyInfoBean();
keyInfo.setCertificate(certs[0]);
keyInfo.setCertIdentifer(CERT_IDENTIFIER.X509_CERT);
return keyInfo;
}
示例2: createKeyInfo
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
protected KeyInfoBean createKeyInfo() throws Exception
{
InputStream is = Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties").openStream();
Properties props = new Properties();
try
{
props.load(is);
}
finally
{
is.close();
}
Crypto crypto = CryptoFactory.getInstance(props);
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias("alice");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
KeyInfoBean keyInfo = new KeyInfoBean();
keyInfo.setCertificate(certs[0]);
keyInfo.setCertIdentifer(CERT_IDENTIFIER.X509_CERT);
return keyInfo;
}
示例3: setKeyIdentifierSKI
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
/**
* Sets the KeyIdentifier Element as a X509 Subject-Key-Identifier (SKI). Takes a X509
* certificate, gets it SKI data, converts into base 64 and inserts it into a
* <code>wsse:KeyIdentifier</code> element, which is placed in the
* <code>wsse:SecurityTokenReference</code> element.
*
* @param cert
* is the X509 certificate to get the SKI
* @param crypto
* is the Crypto implementation. Used to read SKI info bytes from certificate
*/
public void setKeyIdentifierSKI(X509Certificate cert, Crypto crypto) throws WSSecurityException {
//
// As per the 1.1 specification, SKI can only be used for a V3 certificate
//
if (cert.getVersion() != 3) {
throw new WSSecurityException(WSSecurityException.UNSUPPORTED_SECURITY_TOKEN,
"invalidCertForSKI", new Object[] { new Integer(cert.getVersion()) });
}
Document doc = this.element.getOwnerDocument();
byte data[] = crypto.getSKIBytesFromCert(cert);
org.w3c.dom.Text text = doc.createTextNode(Base64.encode(data));
createKeyIdentifier(doc, SKI_URI, text, true);
}
示例4: getX509IssuerSerialAlias
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
/**
* Gets the alias name of the certificate identified with X509 issuerSerial data. The keystore
* identifies the certificate and the key with this alias name.
*
* @return the alias name for the certificate or null if nothing found
*/
public String getX509IssuerSerialAlias(Crypto crypto) throws WSSecurityException {
if (issuerSerial == null) {
issuerSerial = getIssuerSerial();
if (issuerSerial == null) {
return null;
}
}
String alias = crypto.getAliasForX509Cert(issuerSerial.getIssuerName(),
issuerSerial.getSerialNumber());
if (doDebug) {
log.info("X509IssuerSerial alias: " + alias);
}
return alias;
}
示例5: prepare
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
public void prepare(Document doc, Crypto crypto)
throws WSSecurityException, ConversationException {
if (sct == null) {
if (this.identifier != null) {
this.sct = new SecurityContextToken(this.wscVersion, doc, this.identifier);
} else {
this.sct = new SecurityContextToken(this.wscVersion, doc);
this.identifier = this.sct.getIdentifier();
}
}
// The wsu:Id of the wsc:SecurityContextToken
if (this.sctId != null) {
this.sct.setID(this.sctId);
}
}
示例6: handleToken
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
public void handleToken(
Element elem,
Crypto crypto,
Crypto decCrypto,
CallbackHandler cb,
WSDocInfo wsDocInfo,
Vector returnResults,
WSSConfig config
) throws WSSecurityException {
SecurityContextToken sct = new SecurityContextToken(elem);
this.identifier = sct.getIdentifier();
this.secret = this.getSecret(cb, sct);
this.sctId = sct.getID();
returnResults.add(
0,
new WSSecurityEngineResult(WSConstants.SCT, sct)
);
}
示例7: handleToken
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
public void handleToken(
Element elem,
Crypto crypto,
Crypto decCrypto,
CallbackHandler cb,
WSDocInfo wsDocInfo,
Vector returnResults,
WSSConfig wsc
) throws WSSecurityException {
if (log.isDebugEnabled()) {
log.debug("Found SignatureConfirmation list element");
}
//
// Decode SignatureConfirmation, just store in result
//
SignatureConfirmation sigConf = new SignatureConfirmation(elem);
returnResults.add(
0,
new WSSecurityEngineResult(WSConstants.SC, sigConf)
);
scId = elem.getAttributeNS(WSConstants.WSU_NS, "Id");
}
示例8: handleToken
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void handleToken(
Element elem,
Crypto crypto,
Crypto decCrypto,
CallbackHandler cb,
WSDocInfo wsDocInfo,
Vector returnResults,
WSSConfig config
) throws WSSecurityException {
if (crypto == null) {
this.getCertificatesTokenReference(elem, decCrypto);
} else {
this.getCertificatesTokenReference(elem, crypto);
}
returnResults.add(
0,
new WSSecurityEngineResult(WSConstants.BST, this.token, this.certificates)
);
id = elem.getAttributeNS(WSConstants.WSU_NS, "Id");
}
示例9: handleToken
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
public void handleToken(
Element elem,
Crypto crypto,
Crypto decCrypto,
CallbackHandler cb,
WSDocInfo wsDocInfo,
Vector returnResults,
WSSConfig wsc
) throws WSSecurityException {
if (log.isDebugEnabled()) {
log.debug("Found Timestamp list element");
}
wssConfig = wsc;
//
// Decode Timestamp, add the found time (created/expiry) to result
//
Timestamp timestamp = new Timestamp(elem);
handleTimestamp(timestamp);
returnResults.add(
0,
new WSSecurityEngineResult(WSConstants.TS, timestamp)
);
tsId = elem.getAttributeNS(WSConstants.WSU_NS, "Id");
}
示例10: handleToken
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
public void handleToken(Element elem, Crypto crypto, Crypto decCrypto, CallbackHandler cb,
WSDocInfo wsDocInfo, Vector returnResults, WSSConfig wsc) throws WSSecurityException {
if (log.isDebugEnabled()) {
log.debug("Found UsernameToken list element");
}
handleCustomPasswordTypes = wsc.getHandleCustomPasswordTypes();
allowNamespaceQualifiedPasswordTypes = wsc.getAllowNamespaceQualifiedPasswordTypes();
passwordsAreEncoded = wsc.getPasswordsAreEncoded();
Principal lastPrincipalFound = handleUsernameToken((Element) elem, cb);
returnResults.add(
0,
new WSSecurityEngineResult(WSConstants.UT, lastPrincipalFound, null, null, null)
);
utId = ut.getID();
}
示例11: handleToken
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
public final void
handleToken(
final org.w3c.dom.Element elem,
final Crypto crypto,
final Crypto decCrypto,
final javax.security.auth.callback.CallbackHandler cb,
final WSDocInfo wsDocInfo,
final java.util.Vector returnResults,
final WSSConfig config
) throws WSSecurityException {
final java.util.Map result =
new WSSecurityEngineResult(
WSConstants.UT_SIGN,
(SecurityContextToken) null
);
result.put("foo", this);
returnResults.add(result);
}
示例12: testBSTPKIPathSignature
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
/**
* Test that signs and verifies a WS-Security envelope
* <p/>
*
* @throws java.lang.Exception Thrown when there is any problem in signing or verification
*/
public void testBSTPKIPathSignature() throws Exception {
WSSecSignature builder = new WSSecSignature();
builder.setUserInfo("wss40", "security");
builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
builder.setUseSingleCertificate(false);
LOG.info("Before Signing....");
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Crypto pkiCrypto = CryptoFactory.getInstance("wss40.properties");
Document signedDoc = builder.build(doc, pkiCrypto, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("After PKI Signing....");
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
secEngine.processSecurityHeader(doc, null, this, pkiCrypto, null);
}
示例13: loadCryptoFromPropertiesFile
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
/**
* Attempts to resolve the resourcePath using the Spring {@link ResourceLoader}.
* If the resource was not resolved by the {@link ResourceLoader}, falls back to the super implementation (reads
* the resourcePath location as on the classpath).
*
* @see CryptoFactory#getInstance(Properties)
* @see org.apache.cxf.ws.security.wss4j.AbstractWSS4JInterceptor#loadCryptoFromPropertiesFile(java.lang.String, org.apache.ws.security.handler.RequestData)
* @param resourcePath
* @param requestData
* @return the initialized {@link Crypto}
*/
@Override
protected Crypto loadCryptoFromPropertiesFile(String resourcePath, RequestData requestData)
throws WSSecurityException {
Resource resource = resourceLoader.getResource(resourcePath);
if(resource.exists()) {
log.debug("resourceLoader successfully located resource " + resourcePath);
Properties properties = new Properties();
try {
properties.load(resource.getInputStream());
log.debug(resourcePath + " loaded");
return CryptoFactory.getInstance(properties);
} catch (IOException e) {
throw new WSSecurityException("caught IOException while loading resource at " + resourcePath, e);
}
} else {
log.debug("resourceLoader unable to find resource " + resourcePath);
return super.loadCryptoFromPropertiesFile(resourcePath, requestData);
}
}
示例14: loadSignatureCrypto
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
@Override
public Crypto loadSignatureCrypto(RequestData reqData) {
try {
return new Merlin(getMerlinProperties(), ClassLoaderUtils.getDefaultClassLoader());
} catch (Exception e) {
throw new RiceRuntimeException(e);
}
}
示例15: handleOutboundMessage
import org.apache.ws.security.components.crypto.Crypto; //导入依赖的package包/类
private void handleOutboundMessage(SOAPMessageContext context)
throws WSSecurityException, SAXException, IOException {
LOG.debug("adding WS-Security header");
SOAPMessage soapMessage = context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
WSSecHeader wsSecHeader = new WSSecHeader();
wsSecHeader.insertSecurityHeader(soapPart);
WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp();
wsSecTimeStamp.setTimeToLive(60);
wsSecTimeStamp.build(soapPart, wsSecHeader);
Document assertionDocument = this.documentBuilder
.parse(new InputSource(new StringReader(this.samlAssertion)));
Element assertionElement = assertionDocument.getDocumentElement();
String assertionId = assertionElement.getAttribute("AssertionID");
Element importedAssertionElement = (Element) soapPart.importNode(
assertionElement, true);
Element securityHeaderElement = wsSecHeader.getSecurityHeader();
securityHeaderElement.appendChild(importedAssertionElement);
WSSecSignature wsSecSignature = new WSSecSignature();
wsSecSignature.setSignatureAlgorithm(WSConstants.RSA);
wsSecSignature.setKeyIdentifierType(WSConstants.CUSTOM_KEY_IDENTIFIER);
wsSecSignature
.setCustomTokenValueType(WSConstants.WSS_SAML_KI_VALUE_TYPE);
wsSecSignature.setCustomTokenId(assertionId);
Crypto crypto = new WSSecurityCrypto(this.privateKey, null);
wsSecSignature.prepare(soapPart, crypto, wsSecHeader);
Vector<WSEncryptionPart> signParts = new Vector<>();
SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(soapPart
.getDocumentElement());
signParts.add(new WSEncryptionPart(soapConstants.getBodyQName()
.getLocalPart(), soapConstants.getEnvelopeURI(), "Content"));
signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId()));
List<Reference> referenceList = wsSecSignature.addReferencesToSign(
signParts, wsSecHeader);
wsSecSignature.computeSignature(referenceList, false, null);
}