/* * This file is part of SGEA - Sistema de Gestão de Eventos Acadêmicos - TADS IFNMG Campus Januária. * * SGEA 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. * * SGEA 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 SGEA. If not, see <http://www.gnu.org/licenses/>. */ package br.edu.ifnmg.GerenciamentoEventos.Infraestrutura; import br.edu.ifnmg.DomainModel.Services.HashService; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.logging.Level; import java.util.logging.Logger; import javax.ejb.Stateless; /** * * @author petronio */ @Stateless public class HashServiceImpl implements HashService { @Override public String getMD5(String msg) { try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(msg.getBytes()); byte[] digest = md.digest(); StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("%02x", b & 0xff)); } return sb.toString(); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(HashServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } return null; } }