Add the missing statements in the method doCheckSum to get the correct checksum. SHA-1, password, and salt are provided in the main method. Complete the method doCheckSum. The salt needs to be added at the end of the message.
Hashing java.security.MessageDigest
Adding salt to your hash
Report a typo
Sample Input 1:
Sample Output 1:
19182a1bc2570591e594dd1253a9c672453842deWrite a program in Java 25
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
class Main {
private static byte[] doCheckSum(MessageDigest md,
byte[] message,
byte[] salt) {
// Add your code here
return md.digest();
}
// Do not make any changes to the following code.
public static void main(String[] args) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] secret = "MyPassword".getBytes();
byte[] salt = "WildWord".getBytes();
System.out.println(bytesToHex(doCheckSum(md, secret, salt)));
}
public static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.