import java.io.*;
import java.security.*;
import sun.misc.*;

class ComputeMessageDigest {

//Create a simple byte array containing the strings to be computed
static String[] stringBuffer = {"Private Data", "Secure Data"};

public static void main(String[] args) {
//Computar el digest para cada elemento del array de strings
for(int i=0; i<stringBuffer.length; i++)
digestString(i);
}

//Metodo que devuele el digest para una posicion dentro del array
static void digestString (int i){
try{
//Crear objeto MessageDigest con el algoritmo SHA de SUN
MessageDigest md = MessageDigest.getInstance("SHA", "SUN");

md.update(stringBuffer[i].getBytes());

String s = convertBase64(md.digest());
System.out.println("\nEntrada: "+stringBuffer[i]);
System.out.println("\nValor Digest: "+s);
}
catch(Exception e){
System.out.println(e);
System.exit(0);
}
}

static String convertBase64(byte[] data){
BASE64Encoder encoder = new BASE64Encoder();
String encoded = encoder.encodeBuffer(data);
return encoded;
}

}
