SECURITY: SHA1 Hash generating program in java:
SHA1 Hash generating
program in java:
package Security;
import java.math.BigInteger;
import java.security.MessageDigest;
import
java.security.NoSuchAlgorithmException;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class sha1 {
public static String getsha1(String
input) {
try {
MessageDigest md =
MessageDigest.getInstance(“SHA1″);
byte[] messageDigest = md.digest
(input.getBytes());
BigInteger number = new
BigInteger(1, messageDigest);
String hashtext = number.toString
(16);
while (hashtext.length() < 32) {
hashtext = “0″ + hashtext;
}
return hashtext;
}
catch (NoSuchAlgorithmException
e) {
throw new RuntimeException(e);
}
}
public static void main(String[]
args) throws
NoSuchAlgorithmException
{
String
fn=JOptionPane.showInputDialog
(“Enter String for SHA1
Conversion”,”HackingZones”);
JOptionPane.showMessageDialog
(null,getsha1(fn));
// System.out.println(getMD5(fn));
}
}
Comments
Post a Comment