package com.ruoyi.common.encoder;

import com.ruoyi.common.utils.AesUtil;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Objects;

import static com.ruoyi.common.constant.CommonConstants.LOGIN_PASSWORD_AES;

/**
 * @Author: tjf
 * @Date: 2024/4/16 11:05
 * @Describe:
 */
public class AesPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence rawPassword) {
        if (rawPassword == null) {
            throw new IllegalArgumentException("rawPassword cannot be null");
        }
        return AesUtil.encryptCBC(rawPassword.toString(),LOGIN_PASSWORD_AES);
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return Objects.equals(AesUtil.encryptCBC(rawPassword.toString(), LOGIN_PASSWORD_AES), encodedPassword);
    }
}
