bycrypt 加密和校验

bycrypt 加密和校验

import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 加密 校验
 */
public class TestEncrypt {
    public static void main(String[] args) {
        PasswordEncoder delegatingPasswordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        String b1 = delegatingPasswordEncoder.encode("abc");
        String b2 = delegatingPasswordEncoder.encode("abc");
        String b3 = BCrypt.hashpw("abc", BCrypt.gensalt());
        System.out.println(b1);
        System.out.println(b2);
        System.out.println(b1);
        System.out.println(BCrypt.checkpw("abc", b3));
        System.out.println(delegatingPasswordEncoder.matches("abc", b1));
        System.out.println(delegatingPasswordEncoder.matches("abc", b2));
    }
}

你可能感兴趣的:(JAVA,加密解密)