Search in sources :

Example 11 with MessageDigest

use of java.security.MessageDigest in project hadoop by apache.

the class ITestJets3tNativeFileSystemStore method writeRenameReadCompare.

protected void writeRenameReadCompare(Path path, long len) throws IOException, NoSuchAlgorithmException {
    // If len > fs.s3n.multipart.uploads.block.size,
    // we'll use a multipart upload copy
    MessageDigest digest = MessageDigest.getInstance("MD5");
    OutputStream out = new BufferedOutputStream(new DigestOutputStream(fs.create(path, false), digest));
    for (long i = 0; i < len; i++) {
        out.write('Q');
    }
    out.flush();
    out.close();
    assertTrue("Exists", fs.exists(path));
    // Depending on if this file is over 5 GB or not,
    // rename will cause a multipart upload copy
    Path copyPath = path.suffix(".copy");
    fs.rename(path, copyPath);
    assertTrue("Copy exists", fs.exists(copyPath));
    // Download file from S3 and compare the digest against the original
    MessageDigest digest2 = MessageDigest.getInstance("MD5");
    InputStream in = new BufferedInputStream(new DigestInputStream(fs.open(copyPath), digest2));
    long copyLen = 0;
    while (in.read() != -1) {
        copyLen++;
    }
    in.close();
    assertEquals("Copy length matches original", len, copyLen);
    assertArrayEquals("Digests match", digest.digest(), digest2.digest());
}
Also used : Path(org.apache.hadoop.fs.Path) DigestInputStream(java.security.DigestInputStream) BufferedInputStream(java.io.BufferedInputStream) DigestOutputStream(java.security.DigestOutputStream) BufferedInputStream(java.io.BufferedInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) DigestOutputStream(java.security.DigestOutputStream) MessageDigest(java.security.MessageDigest) BufferedOutputStream(java.io.BufferedOutputStream)

Example 12 with MessageDigest

use of java.security.MessageDigest in project hbase by apache.

the class Encryption method hash128.

/**
   * Return the MD5 digest of the concatenation of the supplied arguments.
   */
public static byte[] hash128(byte[]... args) {
    byte[] result = new byte[16];
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        for (byte[] arg : args) {
            md.update(arg);
        }
        md.digest(result, 0, result.length);
        return result;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (DigestException e) {
        throw new RuntimeException(e);
    }
}
Also used : DigestException(java.security.DigestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 13 with MessageDigest

use of java.security.MessageDigest in project hbase by apache.

the class Encryption method hash128.

/**
   * Return the MD5 digest of the concatenation of the supplied arguments.
   */
public static byte[] hash128(String... args) {
    byte[] result = new byte[16];
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        for (String arg : args) {
            md.update(Bytes.toBytes(arg));
        }
        md.digest(result, 0, result.length);
        return result;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (DigestException e) {
        throw new RuntimeException(e);
    }
}
Also used : DigestException(java.security.DigestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 14 with MessageDigest

use of java.security.MessageDigest in project hive by apache.

the class ProxyLocalFileSystem method getMD5Checksum.

/**
   * Calculate MD5 checksum from data in FSDataInputStream
   * @param fsInputStream
   * @return byte array with md5 checksum bytes
   * @throws Exception
   */
static byte[] getMD5Checksum(FSDataInputStream fsInputStream) throws Exception {
    byte[] buffer = new byte[1024];
    MessageDigest md5Digest = MessageDigest.getInstance("MD5");
    int numRead = 0;
    while (numRead != -1) {
        numRead = fsInputStream.read(buffer);
        if (numRead > 0) {
            md5Digest.update(buffer, 0, numRead);
        }
    }
    fsInputStream.close();
    return md5Digest.digest();
}
Also used : MessageDigest(java.security.MessageDigest)

Example 15 with MessageDigest

use of java.security.MessageDigest in project qpid by apache.

the class SchemaClass method generateHash.

/**
     * Return a hash generated over the body of the schema, and return a  representation of the hash
     * @return a hash generated over the body of the schema, and return a  representation of the hash
     */
public final UUID generateHash() {
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        updateHash(md5);
        return UUID.nameUUIDFromBytes(md5.digest());
    } catch (NoSuchAlgorithmException nsae) {
    }
    return null;
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Aggregations

MessageDigest (java.security.MessageDigest)1122 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)562 IOException (java.io.IOException)161 UnsupportedEncodingException (java.io.UnsupportedEncodingException)93 BigInteger (java.math.BigInteger)93 FileInputStream (java.io.FileInputStream)68 InputStream (java.io.InputStream)66 File (java.io.File)58 DigestInputStream (java.security.DigestInputStream)56 Test (org.junit.Test)55 ByteArrayOutputStream (java.io.ByteArrayOutputStream)46 DigestOutputStream (java.security.DigestOutputStream)43 ArrayList (java.util.ArrayList)32 ByteArrayInputStream (java.io.ByteArrayInputStream)29 OutputStream (java.io.OutputStream)27 X509Certificate (java.security.cert.X509Certificate)27 GeneralSecurityException (java.security.GeneralSecurityException)25 Cipher (javax.crypto.Cipher)23 Provider (java.security.Provider)22 SecretKeySpec (javax.crypto.spec.SecretKeySpec)22