Package com.maverick.crypto.digests

Examples of com.maverick.crypto.digests.Hash


        if (qopVariant == QOP_AUTH_INT) {
            throw new IOException(Messages.getString("DigestAuthentication.unsupportedQop")); //$NON-NLS-1$
        }

        Hash hash = new Hash(new MD5Digest());

        // 3.2.2.2: Calculating digest
        StringBuffer tmp = new StringBuffer(uname.length() + realm.length() + pwd.length() + 2);
        tmp.append(uname);
        tmp.append(':');
        tmp.append(realm);
        tmp.append(':');
        tmp.append(pwd);
        // unq(username-value) ":" unq(realm-value) ":" passwd
        String a1 = tmp.toString();
        // a1 is suitable for MD5 algorithm
        if (algorithm.equals("MD5-sess")) { //$NON-NLS-1$
            // H( unq(username-value) ":" unq(realm-value) ":" passwd )
            // ":" unq(nonce-value)
            // ":" unq(cnonce-value)

            hash.putBytes(a1.getBytes("US-ASCII")); //$NON-NLS-1$
            String tmp2 = encode(hash.doFinal());
            StringBuffer tmp3 = new StringBuffer(tmp2.length() + nonce.length() + cnonce.length() + 2);
            tmp3.append(tmp2);
            tmp3.append(':');
            tmp3.append(nonce);
            tmp3.append(':');
            tmp3.append(cnonce);
            a1 = tmp3.toString();
        } else if (!algorithm.equals("MD5")) { //$NON-NLS-1$

        }

        hash.reset();
        hash.putBytes(a1.getBytes("US-ASCII")); //$NON-NLS-1$
        String md5a1 = encode(hash.doFinal());

        String a2 = null;
        if (qopVariant == QOP_AUTH_INT) {
            // we do not have access to the entity-body or its hash
            // TODO: add Method ":" digest-uri-value ":" H(entity-body)
        } else {
            a2 = method + ":" + uri; //$NON-NLS-1$
        }

        hash.reset();
        hash.putBytes(a2.getBytes("US-ASCII")); //$NON-NLS-1$
        String md5a2 = encode(hash.doFinal());

        // 3.2.2.1
        String serverDigestValue;
        if (qopVariant == QOP_MISSING) {

            StringBuffer tmp2 = new StringBuffer(md5a1.length() + nonce.length() + md5a2.length());
            tmp2.append(md5a1);
            tmp2.append(':');
            tmp2.append(nonce);
            tmp2.append(':');
            tmp2.append(md5a2);
            serverDigestValue = tmp2.toString();
        } else {

            String qopOption = getQopVariantString();
            StringBuffer tmp2 = new StringBuffer(md5a1.length() + nonce.length() + NC.length() + cnonce.length()
                + qopOption.length() + md5a2.length() + 5);
            tmp2.append(md5a1);
            tmp2.append(':');
            tmp2.append(nonce);
            tmp2.append(':');
            tmp2.append(NC);
            tmp2.append(':');
            tmp2.append(cnonce);
            tmp2.append(':');
            tmp2.append(qopOption);
            tmp2.append(':');
            tmp2.append(md5a2);
            serverDigestValue = tmp2.toString();
        }

        hash.reset();
        hash.putBytes(serverDigestValue.getBytes("US-ASCII")); //$NON-NLS-1$
        String serverDigest = encode(hash.doFinal());

        return serverDigest;
    }
View Full Code Here


    }

    public static String createCnonce() {

        String cnonce;
        Hash hash = new Hash(new MD5Digest());

        cnonce = Long.toString(System.currentTimeMillis());

        hash.putBytes(cnonce.getBytes());
        cnonce = encode(hash.doFinal());

        return cnonce;
    }
View Full Code Here

        return true;
    }

    private byte[] makePassphraseKey(String passphrase) {
            // Generate the key using the passphrase
            Hash md5 = new Hash("MD5");
            md5.putBytes(passphrase.getBytes());

            byte[] key1 = md5.doFinal();
            md5.reset();
            md5.putBytes(passphrase.getBytes());
            md5.putBytes(key1);

            byte[] key2 = md5.doFinal();
            byte[] key = new byte[32];
            System.arraycopy(key1, 0, key, 0, 16);
            System.arraycopy(key2, 0, key, 16, 16);

            return key;
View Full Code Here

     *
     *
     * @return
     */
    public String getFingerprint() {
            Hash md5 = new Hash("MD5");
            md5.putBytes(getEncoded());

            byte[] digest = md5.doFinal();
            int bits = getBitLength();
            bits = (((bits % 8) != 0) ? (bits += (bits % 8)) : bits);

            String ret = String.valueOf(bits);

View Full Code Here

        lastAccessTime = System.currentTimeMillis();

        /**
         * Generate a unique session id
         */
        Hash hash = new Hash(new MD5Digest());
        hash.putString(String.valueOf(logonTime));
        if(session != null) {
            hash.putString(session.getId());
        }
        hash.putInt(id);
        hash.putString(user.getPrincipalName());
        hash.putString(address.getHostAddress());
        byte[] tmp = hash.doFinal();
        uid = Util.toHexString(tmp);
       
        CoreServlet.getServlet().addCoreListener(this);
    }
View Full Code Here

TOP

Related Classes of com.maverick.crypto.digests.Hash

Copyright © 2018 www.massapicom. 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.