import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.sun.org.apache.xml.internal.security.utils.Base64;
public class getsha1
{
public static void main(String[] args)
{
if (0 == args.length)
{
System.out.println(“usage: “);
System.out.println(“java getsha1 xxxx.xx”);
return;
}
try
{
MessageDigest md = MessageDigest.getInstance("sha-1");
FileInputStream in = new FileInputStream(args[0]);
byte[] buff = new byte[1024];
int readed = -1;
while ((readed = in.read(buff)) > 0)
{
for (int i = 0; i < readed; i++)
md.update(buff[i]);
}
in.close();
System.out.println("Name: " + args[0]);
System.out.println("SHA1-Digest: " + Base64.encode((md.digest())));
}
catch (NoSuchAlgorithmException e)
{
System.out.println(e.toString());
}
catch (FileNotFoundException e)
{
System.out.println(e.toString());
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
}