Hi Guys! I need help figuring out how to correct my code. I'm trying to run a checksum for the first time and I keep running into errors. I hope to figure out how to fix these! The code: package com.snhu.sslserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @SpringBootApplication public class SslServerApplication { publicstaticvoidmain(String[]args){ SpringApplication.run(SslServerApplication.class,args); } } @RestController class SslserverController { @RequestMapping("/hash")
Hi Guys! I need help figuring out how to correct my code. I'm trying to run a checksum for the first time and I keep running into errors. I hope to figure out how to fix these!
The code:
package com.snhu.sslserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@SpringBootApplication
public class SslServerApplication {
publicstaticvoidmain(String[]args){
SpringApplication.run(SslServerApplication.class,args);
}
}
@RestController
class SslserverController {
@RequestMapping("/hash")
publicStringgetHash()throwsNoSuchAlgorithmException{
Stringdata="Hello World, Check Sum!";
Stringname="KT";
String[]splitName=name.split(" ");
StringfirstName=splitName[0];
StringlastName=splitName[splitName.length-1];
name=firstName+" "+lastName;
MessageDigestmd=MessageDigest.getInstance("SHA-256");
byte[]sha256=md.digest(name.getBytes(StandardCharsets.UTF_8));
return"Data: "+data+"<br/><br/>"
+"Name: "+name+"<br/><br/>"
+"Name of cipher
+"CheckSum value: "+bytesToHex(sha256);
}
privateStringbytesToHex(byte[]sha256){
StringBuilderchecksum=newStringBuilder();
for(byteb:sha256){
Stringhex=Integer.toHexString(0xff&b);
if(hex.length()==1)
checksum.append('0');
checksum.append(hex);
}
returnchecksum.toString();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps