package com.ruoyi.common.utils;



import com.ruoyi.common.utils.sign.RsaUtils;

import java.util.Map;

/**
 * @author jianglw
 * @version 1.0
 * @date 2021/1/28 19:47
 */
public class PublicUtils {
    /**
     * 解析map,并加密
     */
    public static Map<String,Object> getEncryptionMap(Map<String,Object> map) throws Exception {
        for(Map.Entry<String,Object> m:map.entrySet()){
            if(m.getValue()instanceof Map){
                getEncryptionMap( (Map<String,Object>)m.getValue() );
            }else{
                if(StringUtils.isNotNull( m.getValue())){
                    m.setValue( RsaUtils.encryptByPrivateKey( m.getValue().toString()) );
                }else{
                    m.setValue("");
                }
            }
        }
        return map;
    }
    /**
     * 解析map,并解密
     */
    public static Map<String,Object> getDecryptMap(Map<String,Object> map) throws Exception {
        for(Map.Entry<String,Object> m:map.entrySet()){
            if(m.getValue()instanceof Map){
                getDecryptMap( (Map<String,Object>)m.getValue() );
            }else{
                if(StringUtils.isNotNull( m.getValue())){
                    m.setValue( RsaUtils.decryptByPublicKey( m.getValue().toString()) );
                    System.out.println(m.getValue());
                }else{
                    m.setValue("");
                }
            }
        }
        return map;
    }
}