Android SHA1 Hash Create sha1(byte[] bytesOfMessage)

Here you can find the source of sha1(byte[] bytesOfMessage)

Description

sha

License

Open Source License

Declaration

public static String sha1(byte[] bytesOfMessage) 

Method Source Code

//package com.java2s;
/* /*from   ww w  .  j a  v a  2  s.c om*/
 * SWRVE CONFIDENTIAL
 * 
 * (c) Copyright 2010-2014 Swrve New Media, Inc. and its licensors.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is and remains the property of Swrve
 * New Media, Inc or its licensors.  The intellectual property and technical
 * concepts contained herein are proprietary to Swrve New Media, Inc. or its
 * licensors and are protected by trade secret and/or copyright law.
 * Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Swrve.
 */

import android.util.Log;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static final String LOG_TAG = "SwrveSDK";

    public static String sha1(byte[] bytesOfMessage) {
        if (bytesOfMessage.length == 0) {
            return null;
        } else {
            try {
                MessageDigest sha1 = MessageDigest.getInstance("SHA1");
                byte[] hash = sha1.digest(bytesOfMessage);

                StringBuilder hexDigest = new StringBuilder();
                for (int i = 0; i < hash.length; i++) {
                    if ((0xFF & hash[i]) < 0x10) {
                        hexDigest.append("0");
                    }
                    hexDigest.append(Integer.toHexString(0xFF & hash[i]));
                }
                return hexDigest.toString();
            } catch (NoSuchAlgorithmException nsae) {
                Log.wtf(LOG_TAG, "Couldn't find SHA1 - what a strange JVM",
                        nsae);
                return "";
            }
        }
    }
}

Related

  1. getSHA1CertFingerprint(Context ctx)
  2. SHA1(String text)
  3. shaByte(String in)
  4. shaByte(byte[] in)
  5. calculateSHA1(byte[] data)
  6. getCertificateSHA1(X509Certificate certificate)
  7. hmacSha1(byte[] value, byte[] key)
  8. computeSHAHash(String password)
  9. encryptByUsingSha1(String passwd)