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


Java Crypto.getCertificates方法代码示例

本文整理汇总了Java中org.apache.ws.security.components.crypto.Crypto.getCertificates方法的典型用法代码示例。如果您正苦于以下问题:Java Crypto.getCertificates方法的具体用法?Java Crypto.getCertificates怎么用?Java Crypto.getCertificates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ws.security.components.crypto.Crypto的用法示例。


在下文中一共展示了Crypto.getCertificates方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepare

import org.apache.ws.security.components.crypto.Crypto; //导入方法依赖的package包/类
/**
 * Prepare the ephemeralKey and the tokens required to be added to the
 * security header
 * 
 * @param doc The SOAP envelope as <code>Document</code>
 * @param crypto An instance of the Crypto API to handle keystore and certificates
 * @throws WSSecurityException
 */
public void prepare(Document doc, Crypto crypto) throws WSSecurityException {

    document = doc;

    //
    // Set up the ephemeral key
    //
    if (this.ephemeralKey == null) {
        this.ephemeralKey = generateEphemeralKey();
    }

    //
    // Get the certificate that contains the public key for the public key
    // algorithm that will encrypt the generated symmetric (session) key.
    //
    X509Certificate remoteCert = null;
    if (useThisCert != null) {
        remoteCert = useThisCert;
    } else {
        X509Certificate[] certs = crypto.getCertificates(user);
        if (certs == null || certs.length <= 0) {
            throw new WSSecurityException(
                WSSecurityException.FAILURE,
                "noUserCertsFound", 
                new Object[] {user, "encryption"}
            );
        }
        remoteCert = certs[0];
    }
    
    prepareInternal(ephemeralKey, remoteCert, crypto);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:41,代码来源:WSSecEncryptedKey.java

示例2: getKeyIdentifier

import org.apache.ws.security.components.crypto.Crypto; //导入方法依赖的package包/类
/**
 * Gets the KeyIdentifier.
 * 
 * @return the the X509 certificate or zero if a unknown key identifier type was detected.
 */
public X509Certificate[] getKeyIdentifier(Crypto crypto) throws WSSecurityException {
	Element elem = getFirstElement();
	String value = elem.getAttribute("ValueType");
	String alias = null;

	if (X509Security.X509_V3_TYPE.equals(value)) {
		X509Security token = new X509Security(elem);
		if (token != null) {
			X509Certificate cert = token.getX509Certificate(crypto);
			X509Certificate[] certs = new X509Certificate[1];
			certs[0] = cert;
			return certs;
		}
	} else if (SKI_URI.equals(value)) {
		alias = getX509SKIAlias(crypto);
	} else if (THUMB_URI.equals(value)) {
		Node node = getFirstElement().getFirstChild();
		if (node == null) {
			return null;
		}
		if (node.getNodeType() == Node.TEXT_NODE) {
			byte[] thumb = Base64.decode(((Text) node).getData());
			alias = crypto.getAliasForX509CertThumb(thumb);
		}
	}

	if (alias != null) {
		return crypto.getCertificates(alias);
	}
	return null;
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:37,代码来源:SecurityTokenReference.java

示例3: getX509IssuerSerial

import org.apache.ws.security.components.crypto.Crypto; //导入方法依赖的package包/类
/**
 * Gets the certificate identified with X509 issuerSerial data. This method first tries to get
 * the embedded certificate. If this fails it checks if the certificate is in the keystore.
 * 
 * @return a certificate array or null if nothing found
 */
public X509Certificate[] getX509IssuerSerial(Crypto crypto) throws WSSecurityException {
	String alias = getX509IssuerSerialAlias(crypto);
	if (alias != null) {
		return crypto.getCertificates(alias);
	}
	return null;
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:14,代码来源:SecurityTokenReference.java

示例4: testInteropKeys1

import org.apache.ws.security.components.crypto.Crypto; //导入方法依赖的package包/类
public void testInteropKeys1() throws Exception {
    Crypto c = CryptoFactory.getInstance("wsstest.properties");
    X509Certificate[] certs = c.getCertificates("alice");
    assertTrue(certs != null);
    assertTrue(certs[0] != null);
    PrivateKey privKey = c.getPrivateKey("alice","password");
    assertTrue(privKey != null);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:9,代码来源:TestInteropKeys.java

示例5: testInteropKeys2

import org.apache.ws.security.components.crypto.Crypto; //导入方法依赖的package包/类
public void testInteropKeys2() throws Exception {
    Crypto c = CryptoFactory.getInstance("wsstest.properties");
    X509Certificate[] certs = c.getCertificates("bob");
    assertTrue(certs != null);
    assertTrue(certs[0] != null);
    PrivateKey privKey = c.getPrivateKey("bob","password");
    assertTrue(privKey != null);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:9,代码来源:TestInteropKeys.java

示例6: prepare

import org.apache.ws.security.components.crypto.Crypto; //导入方法依赖的package包/类
/**
 * Initialize a WSSec Encrypt.
 * 
 * The method prepares and initializes a WSSec Encrypt structure after the
 * relevant information was set. After preparation of the token references
 * can be added and encrypted.
 * 
 * This method does not add any element to the security header. This must be
 * done explicitly.
 * 
 * @param doc The SOAP envelope as <code>Document</code>
 * @param crypto An instance of the Crypto API to handle keystore and certificates
 * @throws WSSecurityException
 */
public void prepare(Document doc, Crypto crypto) throws WSSecurityException {

    document = doc;

    //
    // If no external key (symmetricalKey) was set generate an encryption
    // key (session key) for this Encrypt element. This key will be
    // encrypted using the public key of the receiver
    //
    if (this.ephemeralKey == null) {
        if (symmetricKey == null) {
            KeyGenerator keyGen = getKeyGenerator();
            this.symmetricKey = keyGen.generateKey();
        } 
        this.ephemeralKey = this.symmetricKey.getEncoded();
    }
    
    if (this.symmetricKey == null) {
        this.symmetricKey = WSSecurityUtil.prepareSecretKey(symEncAlgo, this.ephemeralKey);
    }
    
    //
    // Get the certificate that contains the public key for the public key
    // algorithm that will encrypt the generated symmetric (session) key.
    //
    if (this.encryptSymmKey) {
        X509Certificate remoteCert = null;
        if (useThisCert != null) {
            remoteCert = useThisCert;
        } else {
            X509Certificate[] certs = crypto.getCertificates(user);
            if (certs == null || certs.length <= 0) {
                throw new WSSecurityException(
                    WSSecurityException.FAILURE,
                    "noUserCertsFound", 
                    new Object[] { user, "encryption" }
                );
            }
            remoteCert = certs[0];
        }
        prepareInternal(this.ephemeralKey, remoteCert, crypto);
    } else {
        encryptedEphemeralKey = ephemeralKey;
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:60,代码来源:WSSecEncrypt.java


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