# medicare
**Repository Path**: auroraio/medicare
## Basic Information
- **Project Name**: medicare
- **Description**: 医保加密解密starter
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 0
- **Created**: 2024-08-29
- **Last Updated**: 2024-10-28
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 医保加密解密starter
基于`springboot3.x`开发的,只使用了必要的库,没有额外的依赖,使用自动配置减少了使用者的配置,
支持目录的方式配置(推荐),另一种就是像springboot一样的常规配置方式,如果使用这种配置推荐使用三方依赖对配置文件进行加密,
最简单的用法就是直接使用包扫描,配置后面会根据配置文件中的配置自动选择使用的bean配置
## 如何使用
1. 克隆此仓库
```shell
git clone --depth=1 https://gitee.com/auroraio/medicare.git
```
2. 执行打包命令
```shell
mvn clean install -Dmaven.test.skip=true
```
3. 引入依赖
```xml
org.aurora
medicare-spring-boot-starter
${version}
```
4. 配置密钥(以下方式二选一)
1. 在`application.yml`or`application.properties`添加以下内容
* 使用路径配置方式(推荐方式)
```yml
default:
medicare:
type: yaml # properties
path: /opt/keys/config.yml
```
* 使用属性配置方式
```yml
medicare:
enabled: true
app-id: xxx
app-secret: xxx
public-key: xxx
private-key: xxx
version: xxx # default version 2.0.1
```
5. 配置Bean(二选一)
* 使用Java配置方式
```java
@Configuration
public class DefaultMedicareCoreConfigurer {
@Resource
public DefaultMedicareCoreProperties properties;
// 根据配置文件中的类型选择使用
@Bean
public YamlConfigurerLoader yamlConfigurerLoader() {
return new YamlConfigurerLoader(properties);
}
// 根据配置文件中的类型选择使用
@Bean
public PropertiesConfigurerLoader propertiesConfigurerLoader() {
return new PropertiesConfigurerLoader(properties);
}
}
```
* 使用包扫描的方式(推荐方案,会自动根据配置加载对应的bean)
```java
// 记得添加自己的包路径,防止被覆盖
@ComponentScan(basePackages = {"com.demo.*", "org.aurora.autoconfigure.*"})
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
```
6. 使用
```java
@Service
public class DemoService {
public final SMUtils utils;
public DemoService(SMUtils utils) {
this.utils = utils;
}
public String test() {
Map map = new HashMap<>();
map.put("username", "test");
map.put("password", "test");
// 加密
Map encrypt = utils.encrypt(map);
// 加密并验签(解密函数会自动验签,不需要在手动调用)
Object decrypt = utils.decrypt(encrypt);
System.out.println(decrypt);
System.out.println(encrypt.toString());
}
}
```
## 配置文件格式
config.yml
```yml
appId: xxx
appSecret: xxx
publicKey: xxx
privateKey: xxx
version: 2.0.1
```
config.properties
```properties
appId=xxx
appSecret=xxx
publicKey=xxx
privateKey=xxx
version=2.0.1
```