希望示例值一千字。如果没有,下面有几个测试可以在第一个测试中使用盐类种子plainText hello world,在第二个测试中使用static seed to be usedd进行散列。Salt种子用于生成可以传递给BCrypt.hashpw(plainText, staticSalt)函数的静态盐。正如您所看到的,salt字节和salt字节字符串的长度相似,但是它正在抛出一个错误。我知道这是不好的,但我有我的理由静态盐,所以请把你的注意力放在这个问题上。
org.mindrot.jbcrypt.BCrypt与JDK1.7测试1- PlainText:"hello“,saltseed:”静态种子将被使用“
Salt bytes for "static seed to be used": [-30, -8, 86, -8, 6, -126, -64, -30, -82, -82, -104, -64, -8, -118, -64, 108, -82, -64, 14, -30, -82, -104]
Salt bytes string: 4vhW+AaCwOKurpjA+IrAbK7ADuKumA==, length: 32
complete salt: $2a$12$4vhW+AaCwOKurpjA+IrAbK7ADuKumA==
Exception in thread "main" java.lang.IllegalArgumentException: Bad salt length
at org.mindrot.jbcrypt.BCrypt.crypt_raw(BCrypt.java:619)
at org.mindrot.jbcrypt.BCrypt.hashpw(BCrypt.java:684)org.springframework.security.crypto.bcrypt.BCrypt与JDK1.8测试1- PlainText:"hello“,saltseed:”静态种子被使用“
Salt bytes for "static seed to be used": [-30, -8, 86, -8, 6, -126, -64, -30, -82, -82, -104, -64, -8, -118, -64, 108, -82, -64, 14, -30, -82, -104]
Salt bytes string: 4vhW+AaCwOKurpjA+IrAbK7ADuKumA==, length: 32
complete salt: $2a$12$4vhW+AaCwOKurpjA+IrAbK7ADuKumA==
Plain text: hello world, Hash text: $2a$12$4vhWHrTxEMtyyv6wmpOtX.YYbTqHwHv/dxeorg.mindrot.jbcrypt.BCrypt与JDK1.7测试2- PlainText:"hello world",saltseed:“静态种子将被使用”
Salt bytes for "static seed to be usedd": [85, 108, -73, 108, 111, -27, -32, 85, 19, 19, -4, -32, 108, -7, -32, -50, 19, -32, -125, 85, 19, -4]
Salt bytes string: VWy3bG/l4FUTE/zgbPngzhPgg1UT/A==, length: 32
complete salt: $2a$12$VWy3bG/l4FUTE/zgbPngzhPgg1UT/A==
Plain text: hello world, Hash text: $2a$12$VWy3bG/l4FUTE/zgbPngze9KDSXjF72NBMBNE6ZJk4StahyAhykgOorg.springframework.security.crypto.bcrypt.BCrypt与JDK1.8测试2- PlainText:"hello“盐类种子:”静态种子将被使用“
Salt bytes for "static seed to be usedd": [85, 108, -73, 108, 111, -27, -32, 85, 19, 19, -4, -32, 108, -7, -32, -50, 19, -32, -125, 85, 19, -4]
Salt bytes string: VWy3bG/l4FUTE/zgbPngzhPgg1UT/A==, length: 32
complete salt: $2a$12$VWy3bG/l4FUTE/zgbPngzhPgg1UT/A==
Plain text: hello world, Hash text: $2a$12$VWy3bG/l4FUTE/zgbPngze9KDSXjF72NBMBNE6ZJk4StahyAhykgO我试着添加和删除更多的字母,并获得成功的散列。JUnit测试中使用的第一个字符串引发了一个错误,我对此感到高兴。
提前谢谢。
发布于 2018-12-14 17:04:00
我通过查看GitHub页面上的实现找到了原因.BCrypt的这个实现支持base64点(.)字符而不是标准加号(+)字符。
static private final byte index_64[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 0, 1, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, -1, -1,
-1, -1, -1, -1, -1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
-1, -1, -1, -1, -1, -1, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, -1, -1, -1, -1, -1
};"+“字符的整数值为43,因此从该数组返回a-1,而从salt中检索盐字节的函数较早时中断,给我留下了4个字节盐类。甚至它的实现也表示它不支持标准的base64编码字符串:
/**
* Decode a string encoded using bcrypt's base64 scheme to a
* byte array. Note that this is *not* compatible with
* the standard MIME-base64 encoding.
*/
static byte[] decode_base64(String s, int maxolen)
throws IllegalArgumentException {从..。to +给了我一个与Spring不同的散列在含有+的盐类上。不太熟悉shift和&进行更改,因此需要寻找Security的实现。
编辑:只看一下Spring的实现。难怪它不管用..。它完全相同,除非Spring继续使用一个4字节的盐分散列,而jbcrypt抛出一个错误,因此Spring中有一个bug,而如果您生成自己的散列并包含+,那么校验an (plainText,hashedText)将返回false,因为hashtedText中生成的盐部分与用户生成的盐不同。
https://stackoverflow.com/questions/53771795
复制相似问题