You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

54 lines
1.9 KiB

package app.controllers.other;
import app.annotations.interfaces.CheckPermitionFlag;
import app.annotations.interfaces.CheckWebAccess;
import app.utils.CryptedCookie;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/crypto")
public class CryptoController {
private CryptedCookie cryptedCookie;
@Autowired
public CryptoController(CryptedCookie cryptedCookie) {
this.cryptedCookie = cryptedCookie;
}
@CheckWebAccess
@CheckPermitionFlag
@RequestMapping(method = RequestMethod.OPTIONS)
public ResponseEntity checkPermission(HttpServletRequest httpServletRequest) {
return ResponseEntity.ok().build();
}
@PostMapping("/crypt")
@CheckWebAccess
@CheckPermitionFlag
public HashMap<String, String> crypt(HttpServletRequest httpServletRequest, @RequestBody HashMap<String, String> need_crypt) {
return new HashMap<>() {{
need_crypt.entrySet().stream()
.map((item) -> Map.of("key", item.getKey(), "value", cryptedCookie.Hashed(item.getValue())))
.toList()
.forEach((m) -> put(m.get("key"), m.get("value")));
}};
}
@PostMapping("/decrypt")
@CheckWebAccess
@CheckPermitionFlag
public HashMap<String, String> decrypt(HttpServletRequest httpServletRequest, @RequestBody HashMap<String, String> need_decrypt) {
return new HashMap<>() {{
need_decrypt.entrySet().stream()
.map((item) -> Map.of("key", item.getKey(), "value", cryptedCookie.ReadCh(item.getValue())))
.toList()
.forEach((m) -> put(m.get("key"), m.get("value")));
}};
}
}