This Java code provides a method to encrypt strings using the SHA-1 hashing algorithm. The encryptThisString method takes a string as input, uses the SHA-1 MessageDigest to generate a byte array hash, converts it to a hex string, and returns the 32-character encrypted string. The main method calls encryptThisString on two sample strings and prints the results.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
63 views2 pages
SHA1
This Java code provides a method to encrypt strings using the SHA-1 hashing algorithm. The encryptThisString method takes a string as input, uses the SHA-1 MessageDigest to generate a byte array hash, converts it to a hex string, and returns the 32-character encrypted string. The main method calls encryptThisString on two sample strings and prints the results.
public static String encryptThisString(String input) { try { // getInstance() method is called with algorithm SHA-1 MessageDigest md = MessageDigest.getInstance("SHA-1");
// digest() method is called
// to calculate message digest of the input string // returned as array of byte byte[] messageDigest = md.digest(input.getBytes());