org.apache.commons.codec.digest.MessageDigestAlgorithms Java Examples

The following examples show how to use org.apache.commons.codec.digest.MessageDigestAlgorithms. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: chuidiang-ejemplos   Author: chuidiang   File: MD5Example.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

      
      MessageDigest md = MessageDigest.getInstance(MessageDigestAlgorithms.MD5);
      md.update("texto a cifrar".getBytes());
      byte[] digest = md.digest();

      // Se escribe byte a byte en hexadecimal
      for (byte b : digest) {
         System.out.print(Integer.toHexString(0xFF & b));
      }
      System.out.println();

      // Se escribe codificado base 64. Se necesita la librer�a
      // commons-codec-x.x.x.jar de Apache
      byte[] encoded = Base64.encodeBase64(digest);
      System.out.println(new String(encoded));
   }
 
Example #2
Source Project: text_converter   Author: tranleduy2000   File: Digest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void run() throws IOException {
    if (algorithm.equalsIgnoreCase("ALL") || algorithm.equals("*")) {
        run(MessageDigestAlgorithms.values());
        return;
    }
    final MessageDigest messageDigest = DigestUtils.getDigest(algorithm, null);
    if (messageDigest != null) {
        run("", messageDigest);
    } else {
        run("", DigestUtils.getDigest(algorithm.toUpperCase(Locale.ROOT)));
    }
}
 
Example #3
Source Project: pivaa   Author: HTBridge   File: Digest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void run() throws IOException {
    if (algorithm.equalsIgnoreCase("ALL") || algorithm.equals("*")) {
        run(MessageDigestAlgorithms.values());
        return;
    }
    final MessageDigest messageDigest = DigestUtils.getDigest(algorithm, null);
    if (messageDigest != null) {
        run("", messageDigest);
    } else {
        run("", DigestUtils.getDigest(algorithm.toUpperCase(Locale.ROOT)));
    }
}
 
Example #4
Source Project: gatk   Author: broadinstitute   File: FuncotatorDataSourceDownloader.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private NioFileCopierWithProgressMeterResults downloadDataSources(final NioFileCopierWithProgressMeter xerox,
                                                                  final Path checksumPath) {

    // Set up the validity check while the download occurs if requested:
    if ( doValidateIntegrity ) {
        // Read the sha256sum into memory:
        final String expectedSha256Sum = readSha256SumFromPath(checksumPath);

        // Setup the copier to calculate the checksum:
        xerox.setChecksumAlgorithmAndExpectedChecksum(MessageDigestAlgorithms.SHA_256, expectedSha256Sum);
    }

    // Initiate the copy and return our results:
    return xerox.initiateCopy();
}
 
Example #5
Source Project: gatk   Author: broadinstitute   File: NioFileCopierWithProgressMeterResultsUnitTest.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@DataProvider private Object[][] provideForTestFieldGetters() {
    return new Object[][] {
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "tmp2.dict",
                    32,
                    MessageDigestAlgorithms.MD5,
                    "325df528d9103d075413e2aa168a8d8a",
                    true
            },
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "tmp2.dict",
                    32,
                    MessageDigestAlgorithms.SHA_256,
                    "f7deb2461c9a576c432262012c06244bb4384ea0fb3eccfc24991932fb1294f2",
                    true
            },
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "GS:tmp2.dict",
                    32,
                    MessageDigestAlgorithms.MD5,
                    "406129e1186790b08cb0709d9f6f75f22e3bf13550ab7bc2f11c5f21405edae05955ad83b5de33d28333984a898ddc75b6caad71bd0f58f4a0ca03591ff41479",
                    false
            },
            {
                    "GS:benchmark/human_g1k_v37.dict",
                    "GS:testOut.dict",
                    10005,
                    MessageDigestAlgorithms.MD5,
                    "8f04f9288bd8876b8b76a83917ac2725",
                    true
            }
    };
}
 
Example #6
Source Project: judgels   Author: ia-toki   File: JudgelsPlayUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static String hashSHA256(String s) {
    return messageDigest(s, MessageDigestAlgorithms.SHA_256);
}
 
Example #7
Source Project: judgels   Author: ia-toki   File: JudgelsPlayUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static String hashMD5(String s) {
    return messageDigest(s, MessageDigestAlgorithms.MD5);
}
 
Example #8
Source Project: onvif   Author: fpompermaier   File: SimpleSecurityHandler.java    License: Apache License 2.0 4 votes vote down vote up
private static byte[] sha1(String s) throws NoSuchAlgorithmException {
  MessageDigest SHA1 = MessageDigest.getInstance(MessageDigestAlgorithms.SHA_1);
  SHA1.reset();
  SHA1.update(s.getBytes());
  return SHA1.digest();
}
 
Example #9
Source Project: gatk   Author: broadinstitute   File: NioFileCopierWithProgressMeterUnitTest.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@DataProvider
private Object[][] provideForTestChecksumsAndValidateIntegrity() {

    return new Object[][]{
            // Test multiple checksums:
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "tmp2.dict",
                    MessageDigestAlgorithms.MD5,
                    "325df528d9103d075413e2aa168a8d8a",
                    true
            },
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "tmp2.dict",
                    MessageDigestAlgorithms.SHA_256,
                    "f7deb2461c9a576c432262012c06244bb4384ea0fb3eccfc24991932fb1294f2",
                    true
            },
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "tmp2.dict",
                    MessageDigestAlgorithms.SHA_512,
                    "406129e1186790b08cb0709d9f6f75f22e3bf13550ab7bc2f11c5f21405edae05955ad83b5de33d28333984a898ddc75b6caad71bd0f58f4a0ca03591ff41479",
                    true
            },
            // Test checksum mismatches / unexpected values:
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "GS:tmp2.dict",
                    MessageDigestAlgorithms.MD5,
                    "406129e1186790b08cb0709d9f6f75f22e3bf13550ab7bc2f11c5f21405edae05955ad83b5de33d28333984a898ddc75b6caad71bd0f58f4a0ca03591ff41479",
                    false
            },
            {
                    "GS:benchmark/Solexa-272222.bam.md5",
                    "GS:tmp2.dict",
                    MessageDigestAlgorithms.SHA_256,
                    "ASDHFJAIWJOF",
                    false
            },
    };
}