Examples of DerivationAlgorithm


Examples of org.apache.wss4j.common.derivedKey.DerivationAlgorithm

            byte[] seed = new byte[label.length + nonce.length];
            System.arraycopy(label, 0, seed, 0, label.length);
            System.arraycopy(nonce, 0, seed, label.length, nonce.length);

            DerivationAlgorithm derivationAlgorithm;
            try {
                derivationAlgorithm = AlgoFactory.getInstance(WSSConstants.P_SHA_1);
            } catch (ConversationException e) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, e);
            }
           
            final byte[] derivedKeyBytes;
            try {
                byte[] secret;
                if (WSSecurityTokenConstants.SecurityContextToken.equals(wrappingSecurityToken.getTokenType())) {
                    WSPasswordCallback passwordCallback = new WSPasswordCallback(wsuIdDKT, WSPasswordCallback.SECRET_KEY);
                    WSSUtils.doSecretKeyCallback(((WSSSecurityProperties)securityProperties).getCallbackHandler(), passwordCallback, wsuIdDKT);
                    if (passwordCallback.getKey() == null) {
                        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "noKey", wsuIdDKT);
                    }
                    secret = passwordCallback.getKey();
                } else {
                    secret = wrappingSecurityToken.getSecretKey("").getEncoded();
                }

                derivedKeyBytes = derivationAlgorithm.createKey(secret, seed, offset, length);
            } catch (ConversationException e) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, e);
            }

            final GenericOutboundSecurityToken derivedKeySecurityToken =
View Full Code Here

Examples of org.apache.wss4j.common.derivedKey.DerivationAlgorithm

       
        byte[] seed = new byte[label.length + nonce.length];
        System.arraycopy(label, 0, seed, 0, label.length);
        System.arraycopy(nonce, 0, seed, label.length, nonce.length);
       
        DerivationAlgorithm algo =
            AlgoFactory.getInstance(ConversationConstants.DerivationAlgorithm.P_SHA_1);
       
        derivedKeyBytes = algo.createKey(ephemeralKey, seed, offset, length);
       
        // Add the DKTs
        dkt = new DerivedKeyToken(wscVersion, document);
        dktId = getWsConfig().getIdAllocator().createId("DK-", dkt);
       
View Full Code Here

Examples of org.apache.wss4j.common.derivedKey.DerivationAlgorithm

     * @param secret
     * @throws WSSecurityException
     */
    public byte[] deriveKey(int length, byte[] secret) throws WSSecurityException {
        try {
            DerivationAlgorithm algo = AlgoFactory.getInstance(getAlgorithm());
            byte[] labelBytes = null;
            String label = getLabel();
            if (label == null || label.length() == 0) {
                String defaultLabel = ConversationConstants.DEFAULT_LABEL
                    + ConversationConstants.DEFAULT_LABEL;
                labelBytes = defaultLabel.getBytes("UTF-8");
            } else {
                labelBytes = label.getBytes("UTF-8");
            }
           
            byte[] nonce = Base64.decode(getNonce());
            byte[] seed = new byte[labelBytes.length + nonce.length];
            System.arraycopy(labelBytes, 0, seed, 0, labelBytes.length);
            System.arraycopy(nonce, 0, seed, labelBytes.length, nonce.length);
           
            if (length <= 0) {
                length = getLength();
            }
            return algo.createKey(secret, seed, getOffset(), length);
           
        } catch (Exception e) {
            throw new WSSecurityException(
                WSSecurityException.ErrorCode.FAILURE, e
            );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.