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


Java Crypto类代码示例

本文整理汇总了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;
}
 
开发者ID:rareddy,项目名称:ws-security-examples,代码行数:24,代码来源:SamlCallbackHandler.java

示例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;
}
 
开发者ID:windup,项目名称:windup-rulesets,代码行数:24,代码来源:SamlCallbackHandler.java

示例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);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:27,代码来源:SecurityTokenReference.java

示例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;
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:22,代码来源:SecurityTokenReference.java

示例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);
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:18,代码来源:WSSecSecurityContextToken.java

示例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)
    );
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:20,代码来源:SecurityContextTokenProcessor.java

示例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");
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:23,代码来源:SignatureConfirmationProcessor.java

示例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");
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:24,代码来源:BinarySecurityTokenProcessor.java

示例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");
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:25,代码来源:TimestampProcessor.java

示例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();
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:17,代码来源:UsernameTokenProcessor.java

示例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);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:19,代码来源:MyProcessor.java

示例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);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:29,代码来源:TestWSSecurityNew3.java

示例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);
	}
}
 
开发者ID:nblair,项目名称:mule-ws-security-proxy,代码行数:31,代码来源:ResourceLoaderAwareWSS4JInInterceptor.java

示例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);
	}
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:9,代码来源:CXFWSS4JInInterceptor.java

示例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);
}
 
开发者ID:e-Contract,项目名称:mycarenet,代码行数:41,代码来源:WSSecuritySOAPHandler.java


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