quinta-feira, 9 de abril de 2015

Android CriptoSenha - DESEDE/ECB/PKCS5Padding

 public static String CriptoSenha(String Texto, String Chave)
    {
        String SenhaCripto = "";
        try
        {
            //Gera o HASH MD5 da chaveSeguranca
            String encryptionKey = Chave;
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(encryptionKey.getBytes("UTF-8"), 0, encryptionKey.length());
            byte[] encryptionKeyBytes = messageDigest.digest();

            //Instancia o Cripto
            SecretKeySpec Key = new SecretKeySpec(encryptionKeyBytes,"DESede");
            Cipher cipher = Cipher.getInstance("DESEDE/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, Key);
            byte[] encryptedBytes = cipher.doFinal(Texto.getBytes("UTF-8"));

            //Converte para Base64
            SenhaCripto = new String(Base64.encode(encryptedBytes, Base64.DEFAULT), "UTF-8");
        }
        catch(Exception e){

        }
        return SenhaCripto;
    }
Postar um comentário