Example usage for org.bouncycastle.crypto.digests MD5Digest getDigestSize

List of usage examples for org.bouncycastle.crypto.digests MD5Digest getDigestSize

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.digests MD5Digest getDigestSize.

Prototype

public int getDigestSize() 

Source Link

Usage

From source file:com.pmovil.codenameone.nativeshare.Share.java

License:Open Source License

private static String md5(String text) {
    MD5Digest digest = new MD5Digest();
    byte[] data = text.getBytes();
    digest.update(data, 0, data.length);
    byte[] md5 = new byte[digest.getDigestSize()];
    digest.doFinal(md5, 0);//from   w ww .  j  a  v  a2  s  . co  m
    return bytesToHex(md5);
}

From source file:com.yacme.ext.oxsit.cust_it.comp.security.cert.X509CertDisplayBase_IT.java

License:Open Source License

protected void initThumbPrints() {
    //obtain a byte block of the entire certificate data
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    try {//w  ww  .j av  a  2 s.  c o  m
        dOut.writeObject(m_aX509);
        byte[] certBlock = bOut.toByteArray();

        //now compute the certificate SHA1 & MD5 digest
        SHA1Digest digsha1 = new SHA1Digest();
        digsha1.update(certBlock, 0, certBlock.length);
        byte[] hashsha1 = new byte[digsha1.getDigestSize()];
        digsha1.doFinal(hashsha1, 0);
        m_sSHA1Thumbprint = Helpers.printHexBytes(hashsha1);
        MD5Digest digmd5 = new MD5Digest();
        digmd5.update(certBlock, 0, certBlock.length);
        byte[] hashmd5 = new byte[digmd5.getDigestSize()];
        digmd5.doFinal(hashmd5, 0);
        m_sMD5Thumbprint = Helpers.printHexBytes(hashmd5);
    } catch (IOException e) {
        m_aLogger.severe("initThumbPrints", e);
    }
}

From source file:dorkbox.build.Project.java

License:Apache License

/**
 * Generates checksums for the given path
 *//*w w  w .j a  va 2 s  .c om*/
public static final String generateChecksums(Paths... paths) throws IOException {
    synchronized (Project.class) {
        // calculate the hash of all the files in the source path
        Set<String> names = new HashSet<String>(64);

        for (Paths path : paths) {
            names.addAll(path.getPaths());
        }

        // hash of hash of files. faster than using java to hash files
        MD5Digest md5_digest = new MD5Digest();

        boolean found = false;
        for (String name : names) {
            File file = new File(name);
            if (file.isFile() && file.canRead()) {
                found = true;

                byte[] hashBytes = MD5.getHash(file);
                md5_digest.update(hashBytes, 0, hashBytes.length);
            }
        }

        if (!found) {
            return null;
        }

        byte[] hashBytes = new byte[md5_digest.getDigestSize()];
        md5_digest.doFinal(hashBytes, 0);

        String fileChecksums = Base64Fast.encodeToString(hashBytes, false);
        return fileChecksums;
    }
}

From source file:freemail.AccountManager.java

License:Open Source License

public static void changePassword(FreemailAccount account, String newpassword) {
    MD5Digest md5 = new MD5Digest();

    md5.update(newpassword.getBytes(), 0, newpassword.getBytes().length);
    byte[] md5passwd = new byte[md5.getDigestSize()];
    md5.doFinal(md5passwd, 0);/*from  w w  w.j a  v  a  2  s  . c  o  m*/
    String strmd5 = new String(Hex.encode(md5passwd));

    account.getProps().put("md5passwd", strmd5);
}

From source file:freemail.AccountManager.java

License:Open Source License

public FreemailAccount authenticate(String username, String password) {
    if (!(validateUsername(username).equals(""))) {
        return null;
    }//from w w  w  .j av  a  2 s  . c  o m

    FreemailAccount account = null;
    synchronized (accounts) {
        account = accounts.get(username);
    }
    if (account == null)
        return null;

    String realmd5str = account.getProps().get("md5passwd");
    if (realmd5str == null)
        return null;

    MD5Digest md5 = new MD5Digest();
    md5.update(password.getBytes(), 0, password.getBytes().length);
    byte[] givenmd5 = new byte[md5.getDigestSize()];
    md5.doFinal(givenmd5, 0);

    String givenmd5str = new String(Hex.encode(givenmd5));

    if (realmd5str.equals(givenmd5str)) {
        return account;
    }
    return null;
}

From source file:org.fnppl.opensdx.security.SecurityHelper.java

License:Open Source License

public static byte[] getMD5(byte[] data, int off, int len) {
    org.bouncycastle.crypto.digests.MD5Digest md5 = new org.bouncycastle.crypto.digests.MD5Digest();
    byte[] ret = new byte[md5.getDigestSize()];
    md5.update(data, off, len);/*from   w ww.j  a va 2s .  c o m*/
    md5.doFinal(ret, 0);
    return ret;
}

From source file:org.fnppl.opensdx.security.SecurityHelper.java

License:Open Source License

public static byte[] getMD5(InputStream in) {
    org.bouncycastle.crypto.digests.MD5Digest md5 = new org.bouncycastle.crypto.digests.MD5Digest();
    int l = 0;/*from   ww w.j av  a 2  s  .  co m*/
    byte[] buffer = new byte[512];
    try {
        while ((l = in.read(buffer)) > 0) {
            md5.update(buffer, 0, l);
        }
        byte[] ret = new byte[md5.getDigestSize()];
        md5.doFinal(ret, 0);
        return ret;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.freenetproject.freemail.AccountManager.java

License:Open Source License

public static void changePassword(FreemailAccount account, String newpassword) {
    MD5Digest md5 = new MD5Digest();

    try {//  w  w w.  j a  v a2s . c  om
        byte[] passwordBytes = newpassword.getBytes("UTF-8");
        md5.update(passwordBytes, 0, passwordBytes.length);
    } catch (UnsupportedEncodingException e) {
        //JVMs are required to support UTF-8, so we can assume it is always available
        throw new AssertionError("JVM doesn't support UTF-8 charset");
    }
    byte[] md5passwd = new byte[md5.getDigestSize()];
    md5.doFinal(md5passwd, 0);
    String strmd5 = new String(Hex.encode(md5passwd));

    account.getProps().put("md5passwd", strmd5);
}

From source file:org.freenetproject.freemail.AccountManager.java

License:Open Source License

public FreemailAccount authenticate(String username, String password) {
    FreemailAccount account = null;// w  ww.j  a v a 2  s .  c o  m
    synchronized (accounts) {
        account = accounts.get(username);
    }
    if (account == null)
        return null;

    String realmd5str = account.getProps().get("md5passwd");
    if (realmd5str == null)
        return null;

    MD5Digest md5 = new MD5Digest();
    try {
        md5.update(password.getBytes("UTF-8"), 0, password.getBytes("UTF-8").length);
    } catch (UnsupportedEncodingException e) {
        //JVMs are required to support UTF-8, so we can assume it is always available
        throw new AssertionError("JVM doesn't support UTF-8 charset");
    }
    byte[] givenmd5 = new byte[md5.getDigestSize()];
    md5.doFinal(givenmd5, 0);

    String givenmd5str = new String(Hex.encode(givenmd5));

    if (realmd5str.equals(givenmd5str)) {
        return account;
    }
    return null;
}

From source file:org.jclouds.blobstore.functions.impl.BouncyCastleGenerateMD5Result.java

License:Apache License

public MD5InputStreamResult apply(InputStream toEncode) {
    MD5Digest eTag = new MD5Digest();
    byte[] resBuf = new byte[eTag.getDigestSize()];
    byte[] buffer = new byte[1024];
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    long length = 0;
    int numRead = -1;
    try {//  ww  w. j a  va 2  s .  c  o  m
        do {
            numRead = toEncode.read(buffer);
            if (numRead > 0) {
                length += numRead;
                eTag.update(buffer, 0, numRead);
                out.write(buffer, 0, numRead);
            }
        } while (numRead != -1);
    } catch (IOException e) {
        throw new BlobRuntimeException("couldn't get MD5 for: " + toEncode, e);
    } finally {
        IOUtils.closeQuietly(out);
        IOUtils.closeQuietly(toEncode);
    }
    eTag.doFinal(resBuf, 0);
    return new MD5InputStreamResult(out.toByteArray(), resBuf, length);
}