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