@ComponentScan(value="wang.bigbird.domain.framework.common.crypto") @Configuration public class CryptoConfiguration extends Object
构造器和说明 |
---|
CryptoConfiguration() |
限定符和类型 | 方法和说明 |
---|---|
IAesCryptoService |
aesCryptoService(Boolean cacheEnable,
AesModel model,
Byte2StringType converter)
AES对称加密解密器
|
IKeyHolder |
aesKeyHolder(KeyProperty keyProperty)
获取AES key的服务
|
KeyProperty |
aesKeyProperty() |
EnvelopeCryptoService |
envelopCryptoService(IAesCryptoService aesCryptoService,
IRsaCryptoService rsaCryptoService)
数字信封加密解密器
|
void |
init() |
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter |
mappingJackson2HttpMessageConverter()
重写Converter,否则返回string类型带双引号
|
IRsaCryptoService |
rsaCryptoService(Byte2StringType converter)
RSA非对称加密解密器
|
IKeyHolder |
rsaKeyHolder(KeyProperty keyProperty)
获取RSA key的服务
|
KeyProperty |
rsaKeyProperty() |
ISignService |
signService(SignType signType,
Byte2StringType converter)
签名服务
|
ISm4CryptoService |
sm4CryptoService(Byte2StringType converter)
国密SM4加密解密器
|
@PostConstruct public void init()
@ConfigurationProperties(prefix="bigbird.common.crypto.rsa", ignoreInvalidFields=true) @Bean public KeyProperty rsaKeyProperty()
@ConfigurationProperties(prefix="bigbird.common.crypto.aes", ignoreInvalidFields=true) @Bean public KeyProperty aesKeyProperty()
@Bean @ConditionalOnMissingBean(name="rsaKeyHolder") public IKeyHolder rsaKeyHolder(@Qualifier(value="rsaKeyProperty") KeyProperty keyProperty)
@Bean @ConditionalOnMissingBean(name="aesKeyHolder") public IKeyHolder aesKeyHolder(@Qualifier(value="aesKeyProperty") KeyProperty keyProperty)
@Bean @ConditionalOnMissingBean(value=ISignService.class) public ISignService signService(@Value(value="${bigbird.common.crypto.sign.type:MD5}") SignType signType, @Value(value="${bigbird.common.crypto.sign.converter:HEX_LOWER}") Byte2StringType converter)
signType
- 签名算法采用的加密方式converter
- 字节数组转换为字符串的转换方式@Bean @ConditionalOnMissingBean(value=IAesCryptoService.class) public IAesCryptoService aesCryptoService(@Value(value="${bigbird.common.crypto.aes.key.cache-enable:false}") Boolean cacheEnable, @Value(value="${bigbird.common.crypto.aes.model:ECB}") AesModel model, @Value(value="${bigbird.common.crypto.aes.converter:BASE64}") Byte2StringType converter)
cacheEnable
- 是否缓存keymodel
- AES加密模式converter
- 字节码转换器类型@Bean @ConditionalOnMissingBean(value=IRsaCryptoService.class) public IRsaCryptoService rsaCryptoService(@Value(value="${bigbird.common.crypto.rsa.converter:BASE64}") Byte2StringType converter)
converter
- 字节码转换器类型@Bean @ConditionalOnMissingBean(value=Sm4CryptoService.class) public ISm4CryptoService sm4CryptoService(@Value(value="${bigbird.common.crypto.sm4.converter:BASE64}") Byte2StringType converter)
converter
- 字节码转换器类型@Bean @ConditionalOnMissingBean(value=EnvelopeCryptoService.class) public EnvelopeCryptoService envelopCryptoService(@Autowired @Qualifier(value="aesCryptoService") IAesCryptoService aesCryptoService, @Autowired @Qualifier(value="rsaCryptoService") IRsaCryptoService rsaCryptoService)
aesCryptoService
- 对称加密器,用于加密正文rsaCryptoService
- 非对称加密器,用于加密对称密钥@Bean @ConditionalOnMissingBean(value=org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.class) @ConditionalOnProperty(prefix="bigbird.common.crypto.json-convert", name="enable", havingValue="true") public org.springframework.http.converter.json.MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter()