Search in sources :

Example 41 with MessageDigest

use of java.security.MessageDigest in project j2objc by google.

the class MessageDigest2Test method test_getAlgorithm.

/**
     * java.security.MessageDigest#getAlgorithm()
     */
public void test_getAlgorithm() throws Exception {
    for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
        for (String algorithm : e.getValue()) {
            MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
            assertEquals(algorithm, md.getAlgorithm());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MessageDigest(java.security.MessageDigest) Provider(java.security.Provider)

Example 42 with MessageDigest

use of java.security.MessageDigest in project j2objc by google.

the class MessageDigest2Test method test_getDigestLength.

/**
     * java.security.MessageDigest#getDigestLength()
     */
public void test_getDigestLength() throws Exception {
    for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
        for (String algorithm : e.getValue()) {
            MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
            assertTrue("length not ok", md.getDigestLength() > 0);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MessageDigest(java.security.MessageDigest) Provider(java.security.Provider)

Example 43 with MessageDigest

use of java.security.MessageDigest in project liquibase by liquibase.

the class MD5Util method computeMD5.

public static String computeMD5(String input) {
    if (input == null) {
        return null;
    }
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
        digest.update(input.getBytes(LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
    byte[] digestBytes = digest.digest();
    String returnString = new String(encodeHex(digestBytes));
    String inputToLog = input;
    if (inputToLog.length() > 500) {
        inputToLog = inputToLog.substring(0, 500) + "... [truncated in log]";
    }
    LogFactory.getLogger().debug("Computed checksum for " + inputToLog + " as " + returnString);
    return returnString;
}
Also used : GlobalConfiguration(liquibase.configuration.GlobalConfiguration) MessageDigest(java.security.MessageDigest) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 44 with MessageDigest

use of java.security.MessageDigest in project liquibase by liquibase.

the class MD5Util method computeMD5.

public static String computeMD5(InputStream stream) {
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
        DigestInputStream digestStream = new DigestInputStream(stream, digest);
        byte[] buf = new byte[20480];
        while (digestStream.read(buf) != -1) {
            //digest is updating
            ;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    byte[] digestBytes = digest.digest();
    String returnString = new String(encodeHex(digestBytes));
    LogFactory.getLogger().debug("Computed checksum for inputStream as " + returnString);
    return returnString;
}
Also used : DigestInputStream(java.security.DigestInputStream) MessageDigest(java.security.MessageDigest) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 45 with MessageDigest

use of java.security.MessageDigest in project android-common by litesuits.

the class MD5Util method md5.

public static byte[] md5(byte[] bytes) {
    try {
        MessageDigest digest = getDigest("MD5");
        digest.update(bytes);
        return digest.digest();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Aggregations

MessageDigest (java.security.MessageDigest)1237 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)613 IOException (java.io.IOException)176 UnsupportedEncodingException (java.io.UnsupportedEncodingException)102 BigInteger (java.math.BigInteger)101 InputStream (java.io.InputStream)72 FileInputStream (java.io.FileInputStream)70 File (java.io.File)62 DigestInputStream (java.security.DigestInputStream)61 Test (org.junit.Test)61 ByteArrayOutputStream (java.io.ByteArrayOutputStream)51 DigestOutputStream (java.security.DigestOutputStream)45 ArrayList (java.util.ArrayList)37 ByteArrayInputStream (java.io.ByteArrayInputStream)31 X509Certificate (java.security.cert.X509Certificate)29 OutputStream (java.io.OutputStream)28 GeneralSecurityException (java.security.GeneralSecurityException)25 Cipher (javax.crypto.Cipher)25 SecretKeySpec (javax.crypto.spec.SecretKeySpec)25 Provider (java.security.Provider)22