[英]Setting Argon2 algorithm type in Java
Argon2 by default uses Argon2id. Argon2 默认使用 Argon2id。 How can I programatically set a different algorthm type in Java?
如何以编程方式在 Java 中设置不同的算法类型? I mean, how to mention my program should use Argon2i or Argon2d in Java?
我的意思是,如何在 Java 中提到我的程序应该使用 Argon2i 或 Argon2d?
I wanted to encode a password.我想对密码进行编码。 I am using Spring Security jar.
我正在使用 Spring 安全 jar。 Used the below code to create the encoder
使用以下代码创建编码器
Argon2PasswordEncoder encoder = new Argon2PasswordEncoder(DEFAULT_SALT_LENGTH, DEFAULT_HASH_LENGTH, DEFAULT_PARALLELISM, 512, 1000);
This is using argon2id by default.默认情况下使用 argon2id。 Wanted to know how to set a different algorithm.
想知道如何设置不同的算法。
You can use Password4j :您可以使用Password4j :
int memory = 2048;
int iterations = 10;
int parallelism = 1;
int outputLength = 128;
Argon2 variant = Argon2.D;
Argon2Function argon2 = Argon2Function.getInstance(memory, iterations, parallelism, outputLength, variant);
Hash hash = Password.hash(pwd).addRandomSalt().with(argon2);
You can store the configuration in a properties file as well, so you can just write您也可以将配置存储在属性文件中,因此您只需编写
Hash hash = Password.hash(pwd).addRandomSalt().withArgon2();
You can find more information in the official documentation .您可以在官方文档中找到更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.