I am trying to connect to the code I have wrote through my browser, but unfortunately can not figure out how to do so. I have tried 127.0.0.1/hash but it did not work even though I have build the project using maven build compile. was wondering if someone could tell me what am I doing wrong here.
here is the code :
package com.snhu.sslserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
@SpringBootApplication
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
@RestController
class ServerController{
public static String calculateHash(String name) throws NoSuchAlgorithmException
{
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] hash = md.digest(name.getBytes(StandardCharsets.UTF_8));
BigInteger number = new BigInteger(1, hash);
StringBuilder hexString = new StringBuilder(number.toString(16));
while (hexString.length() < 32)
{
hexString.insert(0, '0');
}
return hexString.toString();
}
@RequestMapping("/hash")
public String myHash() throws NoSuchAlgorithmException{
String data = "Hello Kamran Khosravi!";
String hash = calculateHash(data);
return "<p>data:"+data+" : SHA-256 "+" : "+hash;
}
}