Examples of MD5Digest


Examples of bm.core.tools.MD5Digest

     * not stored).
     * @param password clear text passsword
     */
    public void setPassword( final String password )
    {
        MD5Digest md5 = new MD5Digest();
        final byte[] data = password.getBytes();
        md5.update( data, 0, data.length );
        final byte[] digest = new byte[16];
        md5.doFinal( digest, 0 );
        this.password = digest;
    }
View Full Code Here

Examples of bm.core.tools.MD5Digest

     * @throws DBException on error storing the password
     */
    public static void storeEncryptedPassword( final String password )
            throws DBException
    {
        MD5Digest md5 = new MD5Digest();
        final byte[] data = password.getBytes();
        md5.update( data, 0, data.length );
        final byte[] digest = new byte[16];
        md5.doFinal( digest, 0 );
        final LoginInfo info = getLoginInfo();
        info.password = digest;
        info.save();
    }
View Full Code Here

Examples of bm.core.tools.MD5Digest

        final byte[] stored = info.password;
        if( stored != null )
        {
            if( stored.length == 16 )
            {
                MD5Digest md5 = new MD5Digest();
                final byte[] data = challenge.getBytes();
                md5.update( data, 0, data.length );
                final byte[] digest = new byte[16];
                md5.doFinal( digest, 0 );
                for( int i = 0; i < 16; i++ )
                {
                    if( stored[i] != digest[i] )
                    {
                        return false;
View Full Code Here

Examples of com.maverick.crypto.digests.MD5Digest

         * get get better later on
         */

        String magic = "$1$";
        byte finalState[];
        MD5Digest ctx, ctx1;
        long l;

        /* -- */

        /* Refine the Salt first */

        /* If it starts with the magic string, then skip that */

        if (salt.startsWith(magic)) {
            salt = salt.substring(magic.length());
        }

        /* It stops at the first '$', max 8 chars */

        if (salt.indexOf('$') != -1) {
            salt = salt.substring(0, salt.indexOf('$'));
        }

        if (salt.length() > 8) {
            salt = salt.substring(0, 8);
        }

        ctx = new MD5Digest();

        write(ctx, password.getBytes()); // The password first, since that is
                                         // what is most unknown
        write(ctx, magic.getBytes()); // Then our magic string
        write(ctx, salt.getBytes()); // Then the raw salt

        /* Then just as many characters of the MD5(pw,salt,pw) */

        ctx1 = new MD5Digest();
        write(ctx1, password.getBytes());
        write(ctx1, salt.getBytes());
        write(ctx1, password.getBytes());


        finalState = new byte[ctx1.getDigestSize()];
        ctx1.doFinal(finalState, 0);

        for (int pl = password.length(); pl > 0; pl -= 16) {
            for (int i = 0; i < (pl > 16 ? 16 : pl); i++)
                ctx.update(finalState[i]);
        }

        /*
         * the original code claimed that finalState was being cleared to keep
         * dangerous bits out of memory, but doing this is also required in
         * order to get the right output.
         */

        clearbits(finalState);

        /* Then something really weird... */

        for (int i = password.length(); i != 0; i >>>= 1) {
            if ((i & 1) != 0) {
                ctx.update(finalState[0]);
            } else {
                ctx.update(password.getBytes()[0]);
            }
        }

        finalState = new byte[ctx.getDigestSize()];
        ctx.doFinal(finalState, 0);

        /*
         * and now, just to make sure things don't run too fast On a 60 Mhz
         * Pentium this takes 34 msec, so you would need 30 seconds to build a
         * 1000 entry dictionary...
         *
         * (The above timings from the C version)
         */

        for (int i = 0; i < 1000; i++) {
            ctx1 = new MD5Digest();

            if ((i & 1) != 0) {
                write(ctx1, password.getBytes());
            } else {
                for (int c = 0; c < 16; c++)
                    ctx1.update(finalState[c]);
            }

            if ((i % 3) != 0) {
                write(ctx1, salt.getBytes());
            }

            if ((i % 7) != 0) {
                write(ctx1, password.getBytes());
            }

            if ((i & 1) != 0) {
                for (int c = 0; c < 16; c++)
                    ctx1.update(finalState[c]);
            } else {
                write(ctx1, password.getBytes());
            }


            finalState = new byte[ctx.getDigestSize()];
            ctx1.doFinal(finalState, 0);
        }

        /* Now make the output string */

 
View Full Code Here

Examples of com.maverick.crypto.digests.MD5Digest

        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(':');
View Full Code Here

Examples of com.maverick.crypto.digests.MD5Digest

    }

    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());
View Full Code Here

Examples of com.maverick.crypto.digests.MD5Digest

        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);
View Full Code Here

Examples of com.maverick.crypto.digests.MD5Digest

        // #ifdef DEBUG
        log.debug(Messages.getString("SSLHandshakeProtocol.calculatingMasterSecret")); //$NON-NLS-1$
        // #endif

        try {
            MD5Digest md5 = new MD5Digest();
            SHA1Digest sha1 = new SHA1Digest();

            ByteArrayOutputStream out = new ByteArrayOutputStream();

            String[] mixers = new String[] { "A", "BB", "CCC" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

            for (int i = 0; i < mixers.length; i++) {
                md5.reset();
                sha1.reset();
                sha1.update(mixers[i].getBytes(), 0, mixers[i].getBytes().length);
                sha1.update(premasterSecret, 0, premasterSecret.length);
                sha1.update(clientRandom, 0, clientRandom.length);
                sha1.update(serverRandom, 0, serverRandom.length);

                md5.update(premasterSecret, 0, premasterSecret.length);
                byte[] tmp = new byte[sha1.getDigestSize()];
                sha1.doFinal(tmp, 0);

                md5.update(tmp, 0, tmp.length);

                tmp = new byte[md5.getDigestSize()];
                md5.doFinal(tmp, 0);

                out.write(tmp);

            }
View Full Code Here

Examples of com.maverick.crypto.digests.MD5Digest

        length += pendingCipherSuite.getMACLength() * 2;
        length += pendingCipherSuite.getIVLength() * 2;

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        MD5Digest md5 = new MD5Digest();
        SHA1Digest sha1 = new SHA1Digest();

        int turn = 0;
        while (out.size() < length) {
            md5.reset();
            sha1.reset();

            for (int i = 0; i <= turn; i++) {
                sha1.update((byte) ('A' + turn));
            }

            sha1.update(masterSecret, 0, masterSecret.length);
            sha1.update(serverRandom, 0, serverRandom.length);
            sha1.update(clientRandom, 0, clientRandom.length);

            md5.update(masterSecret, 0, masterSecret.length);
            byte[] tmp = new byte[sha1.getDigestSize()];
            sha1.doFinal(tmp, 0);
            md5.update(tmp, 0, tmp.length);
            tmp = new byte[md5.getDigestSize()];
            md5.doFinal(tmp, 0);

            // Write out a block of key data
            out.write(tmp, 0, tmp.length);

            turn++;
View Full Code Here

Examples of com.maverick.crypto.digests.MD5Digest

                            RsaPublicKey r = (RsaPublicKey) trusted.getPublicKey();
                            BigInteger decoded = Rsa.doPublic(input, r.getModulus(), r.getPublicExponent());
                            BigInteger result = Rsa.removePKCS1(decoded, 0x01);
                            byte[] sig = result.toByteArray();

                            MD5Digest digest = new MD5Digest();
                            digest.update(x509.getTBSCertificate(), 0, x509.getTBSCertificate().length);
                            byte[] hash = new byte[digest.getDigestSize()];
                            digest.doFinal(hash, 0);

                            DERInputStream der = new DERInputStream(new ByteArrayInputStream(sig));

                            ASN1Sequence o = (ASN1Sequence) der.readObject();

                            ASN1Sequence o1 = (ASN1Sequence) o.getObjectAt(0);

                            DERObjectIdentifier o2 = (DERObjectIdentifier) o1.getObjectAt(0);
                            ASN1OctetString o3 = (ASN1OctetString) o.getObjectAt(1);

                            byte[] actual = o3.getOctets();

                            for (int i = 0; i < actual.length; i++) {
                                if (actual[i] != hash[i]) {
                                    return false;
                                }
                            }

                        } catch (IOException ex1) {
                            throw new SSLException(SSLException.INTERNAL_ERROR, ex1.getMessage());
                        }

                    } else if (x509.getSigAlgName().equals("SHA1WithRSAEncryption")) { //$NON-NLS-1$

                        try {
                            byte[] blob = x509.getSignature();

                            // Check for signed bit
                            if ((blob[0] & 0x80) == 0x80) {
                                blob = new byte[x509.getSignature().length + 1];
                                blob[0] = 0;
                                System.arraycopy(x509.getSignature(), 0, blob, 1, x509.getSignature().length);
                            }

                            BigInteger input = new BigInteger(blob);
                            RsaPublicKey r = (RsaPublicKey) trusted.getPublicKey();

                            BigInteger decoded = Rsa.doPublic(input, r.getModulus(), r.getPublicExponent());

                            BigInteger result = Rsa.removePKCS1(decoded, 0x01);
                            byte[] sig = result.toByteArray();

                            SHA1Digest digest = new SHA1Digest();
                            digest.update(x509.getTBSCertificate(), 0, x509.getTBSCertificate().length);
                            byte[] hash = new byte[digest.getDigestSize()];
                            digest.doFinal(hash, 0);

                            DERInputStream der = new DERInputStream(new ByteArrayInputStream(sig));

                            ASN1Sequence o = (ASN1Sequence) der.readObject();
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.