package com.simuwang.manage.api;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import com.simuwang.base.config.DaqProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {
    private final DaqProperties properties;

    public TestController(DaqProperties properties) {
        this.properties = properties;
    }

    @GetMapping("hello")
    public String test() {
        return "hello";
    }

    @GetMapping("rsa")
    public String rsa(@RequestParam("str") String str) {
        String publicKey = this.properties.getSecurityRsa().getPublicKey();
        return new RSA(null, publicKey).encryptBase64(str, KeyType.PublicKey);
    }
}
