parent
edd6dcec59
commit
e8f9f15b39
@ -0,0 +1,25 @@
|
|||||||
|
package org.opsli.core.autoconfigure.properties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密配置加载
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2022-08-07
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = EncryptProperties.PROP_PREFIX)
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class EncryptProperties {
|
||||||
|
|
||||||
|
public static final String PROP_PREFIX = "opsli.data-encrypt";
|
||||||
|
|
||||||
|
/** 秘钥 */
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.options;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.opsli.common.annotation.OptionDict;
|
||||||
|
import org.opsli.common.annotation.validator.Validator;
|
||||||
|
import org.opsli.common.enums.ValidatorType;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
import org.opsli.core.utils.ValidatorUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云短信-验证码配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
public enum SmsAliYunCaptchaConfigFactory {
|
||||||
|
|
||||||
|
/** 实例对象 */
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return LocalConfig
|
||||||
|
*/
|
||||||
|
public SmsAliYunCaptchaConfigOption getConfig() {
|
||||||
|
SmsAliYunCaptchaConfigOption option = new SmsAliYunCaptchaConfigOption();
|
||||||
|
// 获得缓存参数配置
|
||||||
|
OptionsUtil.getOptionByBean(option);
|
||||||
|
// 验证配置
|
||||||
|
ValidatorUtil.verify(option);
|
||||||
|
|
||||||
|
// 转化对象
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云短信验证码配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class SmsAliYunCaptchaConfigOption implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 模版编码 */
|
||||||
|
@ApiModelProperty(value = "模版编码")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("sms_aliyun_captcha_template_code")
|
||||||
|
private String templateCode;
|
||||||
|
|
||||||
|
/** 签名 */
|
||||||
|
@ApiModelProperty(value = "签名")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("sms_aliyun_captcha_sign")
|
||||||
|
private String sign;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.options;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.opsli.common.annotation.OptionDict;
|
||||||
|
import org.opsli.common.annotation.validator.Validator;
|
||||||
|
import org.opsli.common.enums.ValidatorType;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
import org.opsli.core.utils.ValidatorUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云短信配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
public enum SmsAliYunConfigFactory {
|
||||||
|
|
||||||
|
/** 实例对象 */
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return LocalConfig
|
||||||
|
*/
|
||||||
|
public SmsAliYunConfigOption getConfig() {
|
||||||
|
SmsAliYunConfigOption option = new SmsAliYunConfigOption();
|
||||||
|
// 获得缓存参数配置
|
||||||
|
OptionsUtil.getOptionByBean(option);
|
||||||
|
// 验证配置
|
||||||
|
ValidatorUtil.verify(option);
|
||||||
|
|
||||||
|
// 转化对象
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云短信配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class SmsAliYunConfigOption implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** access_key */
|
||||||
|
@ApiModelProperty(value = "阿里云AccessKey")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("sms_aliyun_access_key")
|
||||||
|
private String accessKey;
|
||||||
|
|
||||||
|
/** access_key_secret */
|
||||||
|
@ApiModelProperty(value = "阿里云AccessKeySecret")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("sms_aliyun_access_key_secret")
|
||||||
|
private String accessKeySecret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package opsli.plugins.crypto.spring.crypto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密解密器 可自行实现
|
||||||
|
*
|
||||||
|
* @author zhangylo
|
||||||
|
*/
|
||||||
|
public interface ICrypto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*
|
||||||
|
* @param value 加密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 加密后的值
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
String encrypt(String value, String key) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param value 解密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 解密后的值
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
String decrypt(String value, String key) throws Exception;
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package opsli.plugins.crypto.spring.crypto.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import opsli.plugins.crypto.CryptoPlugin;
|
||||||
|
import opsli.plugins.crypto.enums.CryptoSymmetricType;
|
||||||
|
import opsli.plugins.crypto.model.CryptoSymmetric;
|
||||||
|
import opsli.plugins.crypto.spring.crypto.ICrypto;
|
||||||
|
import opsli.plugins.crypto.strategy.CryptoSymmetricService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AES 加密解密器
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2022-08-07 17:33
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class AESCrypto implements ICrypto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*
|
||||||
|
* @param value 加密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 加密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String encrypt(String value, String key) throws Exception {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.AES)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.encrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param value 解密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 解密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String decrypt(String value, String key) {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.AES)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.decrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package opsli.plugins.crypto.spring.crypto.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import opsli.plugins.crypto.CryptoPlugin;
|
||||||
|
import opsli.plugins.crypto.enums.CryptoSymmetricType;
|
||||||
|
import opsli.plugins.crypto.model.CryptoSymmetric;
|
||||||
|
import opsli.plugins.crypto.spring.crypto.ICrypto;
|
||||||
|
import opsli.plugins.crypto.strategy.CryptoSymmetricService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DES 加密解密器
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2022-08-07 17:33
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class DESCrypto implements ICrypto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*
|
||||||
|
* @param value 加密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 加密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String encrypt(String value, String key) throws Exception {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.DES)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.encrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param value 解密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 解密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String decrypt(String value, String key) {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.DES)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.decrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package opsli.plugins.crypto.spring.crypto.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import opsli.plugins.crypto.CryptoPlugin;
|
||||||
|
import opsli.plugins.crypto.enums.CryptoSymmetricType;
|
||||||
|
import opsli.plugins.crypto.model.CryptoSymmetric;
|
||||||
|
import opsli.plugins.crypto.spring.crypto.ICrypto;
|
||||||
|
import opsli.plugins.crypto.strategy.CryptoSymmetricService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DES 加密解密器
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2022-08-07 17:33
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class DESEDECrypto implements ICrypto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*
|
||||||
|
* @param value 加密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 加密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String encrypt(String value, String key) throws Exception {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.DE_SEDE)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.encrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param value 解密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 解密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String decrypt(String value, String key) {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.DE_SEDE)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.decrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package opsli.plugins.crypto.spring.crypto.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import opsli.plugins.crypto.CryptoPlugin;
|
||||||
|
import opsli.plugins.crypto.enums.CryptoSymmetricType;
|
||||||
|
import opsli.plugins.crypto.model.CryptoSymmetric;
|
||||||
|
import opsli.plugins.crypto.spring.crypto.ICrypto;
|
||||||
|
import opsli.plugins.crypto.strategy.CryptoSymmetricService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 国密4 加密解密器
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2022-08-07 17:33
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class SM4Crypto implements ICrypto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*
|
||||||
|
* @param value 加密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 加密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String encrypt(String value, String key) throws Exception {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.SM4)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.encrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param value 解密前的值
|
||||||
|
* @param key 秘钥
|
||||||
|
* @return 解密后的值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String decrypt(String value, String key) {
|
||||||
|
CryptoSymmetric cryptoSymmetric = CryptoSymmetric.builder()
|
||||||
|
.cryptoType(CryptoSymmetricType.SM4)
|
||||||
|
.privateKey(key)
|
||||||
|
.build();
|
||||||
|
CryptoSymmetricService symmetric = CryptoPlugin.getSymmetric();
|
||||||
|
return symmetric.decrypt(cryptoSymmetric, value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package opsli.plugins.crypto.spring.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密解密枚举
|
||||||
|
*
|
||||||
|
* @author zhangylo
|
||||||
|
*/
|
||||||
|
public enum CryptoType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ENCRYPT 加密
|
||||||
|
* DECRYPT 解密
|
||||||
|
*/
|
||||||
|
ENCRYPT("com/encrypt"), DECRYPT("decrypt");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对应加密器方法名称
|
||||||
|
*/
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
CryptoType(String method) {
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethod(String method) {
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
}
|
@ -1,43 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.sms.conf;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 阿里云 配置文件
|
|
||||||
*
|
|
||||||
* @author yanxiaojian
|
|
||||||
* @date 2021-06-10
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = AliYunSmsProperties.PROP_PREFIX)
|
|
||||||
public class AliYunSmsProperties {
|
|
||||||
|
|
||||||
public static final String PROP_PREFIX = "sms.aliyun";
|
|
||||||
|
|
||||||
/** 主账号id */
|
|
||||||
private String accessKeyId;
|
|
||||||
|
|
||||||
/** 密钥 */
|
|
||||||
private String accessKeySecret;
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue