Java Digest digest(final @Nullable String[] tokens, @Nullable final Date[] dates)

Here you can find the source of digest(final @Nullable String[] tokens, @Nullable final Date[] dates)

Description

digest

License

EUPL

Declaration

private static byte[] digest(final @Nullable String[] tokens, @Nullable final Date[] dates) throws IOException 

Method Source Code


//package com.java2s;
/*/*  w  ww.j  a v  a 2s. c o m*/
 * Copyright 2013 Institute for Molecular Imaging Instrumentation (I3M)
 * 
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by 
 * the European Commission - subsequent versions of the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 * 
 *   http://ec.europa.eu/idabc/eupl
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and 
 * limitations under the Licence.
 * 
 * This product combines work with different licenses. See the "NOTICE" text
 * file for details on the various modules and licenses.
 * The "NOTICE" text file is part of the distribution. Any derivative works
 * that you distribute must include a readable copy of the "NOTICE" text file.
 */

import java.io.IOException;
import java.security.MessageDigest;
import java.util.Date;
import javax.annotation.Nullable;

public class Main {
    private static byte[] digest(final @Nullable String[] tokens, @Nullable final Date[] dates) throws IOException {
        try {
            String mixName = "";
            if (tokens != null) {
                for (final String token : tokens) {
                    mixName += (token != null ? token.trim() : "");
                }
            }
            if (dates != null) {
                for (final Date date : dates) {
                    mixName += (date != null ? Long.toString(date.getTime()) : "");
                }
            }
            // compute digest
            final byte[] bytesOfMixName = mixName.getBytes("UTF-8");
            final MessageDigest md = MessageDigest.getInstance("SHA");
            return md.digest(bytesOfMixName);
        } catch (Exception e) {
            throw new IOException("Digest computation has failed", e);
        }
    }
}

Related

  1. digest(byte[] data, String algorithm)
  2. digest(byte[] input)
  3. digest(byte[] input, final String algorithm)
  4. digest(byte[] input, String algorithm, byte[] salt, int iterations)
  5. digest(byte[] message, String hash_alg)
  6. digest(final byte[] data)
  7. digest(final InputStream inputStream, final MessageDigest digester)
  8. digest(final java.security.MessageDigest messageDigest, final java.nio.ByteBuffer data)
  9. digest(final String algorithm, final byte[] bytes)