分类 技术相关 下的文章

News on September 22, today, at the International Cloud Summit held in Thailand, Alibaba Cloud announced that it will continue to accelerate its overseas market layout, invest 7 billion yuan in the next three years to build an international localized ecosystem, and add 6 overseas service centers. Porto, Mexico City, Kuala Lumpur, Dubai, etc.

Alibaba Cloud's
In the past year, Alibaba Cloud has added seven overseas data centers in South Korea, Thailand, Germany, Indonesia, the Philippines, and Saudi Arabia. Currently, Alibaba Cloud operates 85 availability zones in 28 regions around the world, covering more than 200 countries and regions around the world.

In terms of product technology, Alibaba Cloud announced the launch of the eighth-generation ECS cloud server, cloud box, enterprise networking CEN2.0, container service ACK ONE, self-developed database PolarDB-X, self-developed multimodal database Lindorm and other international versions.

According to Canalys data, spending on cloud infrastructure services in mainland China increased by 11% year-on-year to reach $7.3 billion in the second quarter of 2022, accounting for 12% of overall global cloud spending. Among them, Alibaba Cloud accounted for 34% of the market share this quarter, an increase of about 10% year-on-year.

springboot
使用springcloud的时候要注意spring cloud和spring boot的版本是有对应关系的,如果使用了不对应的版本,往往会导致一些奇奇怪怪得bug;
具体对应关系可以通过官方给的网址来获取:https://start.spring.io/actuator/info
访问该网址后可以得到一个json,通过这个json来获得对应版本,格式化可以使用https://www.bejson.com/进行格式化
例如:查看Spring cloud和spring boot的版本对应关系:
spring cloud和spring boot的版本

17042-2ipydmtus8e.png

docker exec 的使用-it操作
首先进入容器:
docker命令
docker exec -it CONTAINER_ID bash 进入容器终端并且的保留为容器终端的输入形式(-it和bash的结合作用)

官方解释:
exec: Run a command in a running container(在运行的容器中运行命令)
exec -i: --interactive(相互作用的)
exec -t: --tty Allocate a pseudo-TTY(分配一个 冒充的终端设备)
CONTAINER_ID : 容器id只要是能够证明唯一就可以,不用全输入例子:

查看正在运行的容器:

docker Ps

进入容器

进入容器命令
docker exec -it CONTAINER_ID bash 进入容器终端并且的保留为容器终端的输入形式.

1.抽象类

跟普通类没啥区别,只是多了抽象方法。不能new。
属于顶层设计,定义出共有的属性和方法。含有抽象方法一定是抽象类

抽象类跟接口区别

2.接口

更严格,不能new,定义的变量都是常量 public static final,默认的可忽略
只能有抽象方法,默认就是public abstract 可以忽略。
不能有构造方法
jdk1.8之后,放宽条件、
可以 defalut关键字声明普通方法、静态方法

使用场景:
抽象类,一般用于含有共有属性及功能的抽取,如人。java是单继承,继承后可以有男人女人

接口,可以多实现、继承,解耦,多态。 动物>>狗和猫,而狗和猫的差别很大,属于多态。

父接口引用,指向一个具体的实现类,体现多态,如参数是接口,但是传入的类型可以是不同的实现类。
同理。父类指向一个子类的引用,可以调用父类方法,要想调用子类方法,需要向下转型。

一、背景
在我们数据库中有些时候会保存一些用户的敏感信息,比如:手机号、银行卡等信息,如果这些信息以明文的方式保存,那么是不安全的。假如:黑客黑进了数据库,或者离职人员导出了数据,那么就可能导致这些敏感数据的泄漏。因此我们就需要找到一种方法来解决这个问题。

二、解决方案
由于我们系统中使用了Mybatis作为数据库持久层,因此决定使用Mybatis的TypeHandler或Plugin来解决。

TypeHandler : 需要我们在某些列上手动指定 typeHandler 来选择使用那个typeHandler或者根据@MappedJdbcTypes 和 @MappedTypes注解来自行推断。
<result column="phone" property="phone"
typeHandler="com.huan.study.mybatis.typehandler.EncryptTypeHandler"/>

Plugin : 可以拦截系统中的 select、insert、update、delete等语句,也能获取到sql执行前的参数和执行后的数据。
经过考虑,决定使用TypeHandler来加解密数据。

    /**
 * 加解密TypeHandler
 *
 * @author huan.fu 2021/5/18 - 上午9:20
 */
@MappedJdbcTypes(JdbcType.VARCHAR)
@MappedTypes(Encrypt.class)
public class EncryptTypeHandler extends BaseTypeHandler<Encrypt> {

    private static final byte[] KEYS = "12345678abcdefgh".getBytes(StandardCharsets.UTF_8);

    /**
     * 设置参数
     */
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Encrypt parameter, JdbcType jdbcType) throws SQLException {
        if (parameter == null || parameter.getValue() == null) {
            ps.setString(i, null);
            return;
        }
        AES aes = SecureUtil.aes(KEYS);
        String encrypt = aes.encryptHex(parameter.getValue());
        ps.setString(i, encrypt);
    }

    /**
     * 获取值
     */
    @Override
    public Encrypt getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return decrypt(rs.getString(columnName));
    }

    /**
     * 获取值
     */
    @Override
    public Encrypt getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return decrypt(rs.getString(columnIndex));
    }

    /**
     * 获取值
     */
    @Override
    public Encrypt getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return decrypt(cs.getString(columnIndex));
    }

    public Encrypt decrypt(String value) {
        if (null == value) {
            return null;
        }
        return new Encrypt(SecureUtil.aes(KEYS).decryptStr(value));
    }
}

注意⚠️:

@MappedTypes:表示该处理器处理的java类型是什么。
@MappedJdbcTypes:表示处理器处理的Jdbc类型。

配置文件中指定Typehandler的包路径

mybatis.type-handlers-package=com.huan.study.mybatis.typehandler

36247-s83jc7mzx6o.png

从测试结果中可知,添加数据时,需要加密的数据(phone)在数据库中已经加密了,在查询的时候,加密的数据已经自动解密了。

实现代码参考

https://gitee.com/huan1993/spring-cloud-parent/tree/master/mybatis/mybatis-typehandler-encrypt

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。