Search in sources :

Example 1 with LicenseCheckModel

use of com.chao.cloud.common.extra.license.LicenseCheckModel in project chao-cloud by chaojunzi.

the class LicenseController method upload.

@PostMapping(value = "upload")
public Response<LicenseCheckModel> upload(@NotNull MultipartFile licenseFile) {
    String ciphertext = null;
    try (InputStream in = licenseFile.getInputStream()) {
        // 获取密文
        ciphertext = IoUtil.readUtf8(in);
        Assert.notBlank(ciphertext, "licesne密文解析失败");
        // 解析证书内容
        String json = config.getRsa().decryptStr(ciphertext, KeyType.PrivateKey);
        LicenseCheckModel checkModel = JSONUtil.toBean(json, LicenseCheckModel.class);
        return Response.ok(checkModel);
    } catch (Exception e) {
        throw new BusinessException(StrUtil.format("[证书生成失败! error={},无效的密文:{}]", e.getMessage(), ciphertext));
    }
}
Also used : BusinessException(com.chao.cloud.common.exception.BusinessException) InputStream(java.io.InputStream) LicenseCheckModel(com.chao.cloud.common.extra.license.LicenseCheckModel) BusinessException(com.chao.cloud.common.exception.BusinessException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

BusinessException (com.chao.cloud.common.exception.BusinessException)1 LicenseCheckModel (com.chao.cloud.common.extra.license.LicenseCheckModel)1 InputStream (java.io.InputStream)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1