SHA-1 string : SHA « Security « Android






SHA-1 string

    
/* Copyright (c) 2010 ARTags Project owners (see http://www.artags.org)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//package org.artags.android.app.util.security;

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

/**
 *
 * @author pierre
 */
public class SecurityUtils
{

    public static String sha1(String data)
    {
        try
        {
            byte[] b = data.getBytes();
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.reset();
            md.update(b);
            byte messageDigest[] = md.digest();
            StringBuilder result = new StringBuilder();
            for (int i = 0; i < messageDigest.length; i++)
            {
                result.append(Integer.toString((messageDigest[i] & 0xff) + 0x100, 16).substring(1));
            }

            return result.toString();

        } catch (NoSuchAlgorithmException e)
        {

          //  Log.e("ARTags", "SHA1 is not a supported algorithm");
        }
        return null;
    }
}

   
    
    
    
  








Related examples in the same category

1.hmac Sha1 Digest
2.Sha1 hashes based on a given String
3.SHA1 Utils
4.Using SharedPreferences to store password
5.Using SharedPreferences
6.Drawing Shapes
7.Animated wallpaper draws a rotating wireframe shape with a choice of 2 shapes
8.Animation: shake
9.Get reference from SharedPreferences
10.Glutes shape
11.Reshaping Arabic Sentences and Text Utilities to deal with Arabic
12.Save SharedPreferences
13.Save value to SharedPreferences
14.SharedPreferences Set and get value
15.Compute the SHA-1 hash of the given byte array
16.compute SHA-1 Hash