package com.dxhy.admin.sys.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.jasypt.encryption.StringEncryptor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jiaohongyang
 */
@RestController
@RequestMapping("jasypt")
@Slf4j
public class JasyptPasswordController {
    @Resource
    private StringEncryptor stringEncryptor;

    @RequestMapping(value = "/getJasypt", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, String> getJasypt(String jasypt, String name, String password) {
        Map<String, String> map = new HashMap<>(3);
        String encrypt = stringEncryptor.encrypt(jasypt);
        map.put(jasypt, encrypt);

        map.put(stringEncryptor.decrypt(name), name);
        map.put(stringEncryptor.decrypt(password), password);
        return map;
    }

}
