首页 > 解决方案 > Elasticsearch 异常 [type=illegal_argument_exception, reason=Provided password hash uses [NOOP] but the configured hashing algorithm is [BCRYPT]]

问题描述

我正在尝试使用 Java Spring Boot 应用程序创建一个新的 Elasticsearch 用户。但显示以下错误:

Elasticsearch 异常 [type=illegal_argument_exception, reason=Provided password hash uses [NOOP] but the configured hashing algorithm is [BCRYPT]]

我正在执行以下操作:

    public String create(ElasticUser newUser) {
        try {
        byte[] salt = new byte[16];
        RANDOM.nextBytes(salt);
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2withHMACSHA512");
        PBEKeySpec keySpec = new PBEKeySpec("password".toCharArray(), salt, 10000, 256);
        final byte[] pbkdfEncoded = secretKeyFactory.generateSecret(keySpec).getEncoded();
        char[] passwordHash = ("{PBKDF2}10000$" + Base64.getEncoder().encodeToString(salt)
                + "$" + Base64.getEncoder().encodeToString(pbkdfEncoded)).toCharArray();
        User user = new User(newUser.getName(), new ArrayList<>(Arrays.asList("normal_user")));
        PutUserRequest request = PutUserRequest.withPasswordHash(user
                , passwordHash
                , true
                , RefreshPolicy.NONE);
        PutUserResponse response = restHighLevelClient.security().putUser(request, RequestOptions.DEFAULT);
        return response.toString();
        } catch(Exception e) {
            return "Error: " + e.getMessage();
        }
    }

关于这个问题的任何想法?

标签: javaelasticsearchpasswordspassword-hash

解决方案


推荐阅读