第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

可以在 BCrypt 中設(shè)置明文或?qū)⑵滢D(zhuǎn)換為鹽嗎?

可以在 BCrypt 中設(shè)置明文或?qū)⑵滢D(zhuǎn)換為鹽嗎?

qq_花開花謝_0 2023-06-21 13:57:02
我對密碼加密練習(xí)有一個(gè)要求,其中密碼的鹽是靜態(tài)的,并business_id+business_start_date根據(jù)客戶的企業(yè) ID 和開始日期設(shè)置為 ( ) 值。在 BCrypt 文檔中,據(jù)說 BCrypt 在生成的哈希值中內(nèi)置了鹽,以防止彩虹表攻擊。大多數(shù)示例使用 gensalt(int log_rounds) 函數(shù)。IMO,我肯定會(huì)像其他人一樣使用動(dòng)態(tài)鹽,因?yàn)樗菀讓?shí)現(xiàn)。但是,如果仍然堅(jiān)持實(shí)施靜態(tài)鹽散列,是否有辦法讓 BCrypt 接受靜態(tài)散列或;如果不可能,我可以使用哪些其他加密來滿足該要求?該應(yīng)用主要是80%的閱讀內(nèi)容,少量的創(chuàng)建、更新、刪除操作。我剛剛做了一個(gè)測試,嘗試使用靜態(tài)鹽對密碼進(jìn)行哈希處理。該方法在 BCrypt 實(shí)用程序類中使用:public static String hashPassWord(String textPassword, String salt){        String hashPassword = BCrypt.hashpw(textPassword, salt);        return hashPassword;}我正在測試的鹽是純文本格式的,例如(busId:3,businessDate:2019-02-04)String salt = new StringBuilder(busId).append(businessDate).toString();我也有這個(gè)方法作為備用,輪數(shù)(工作量)設(shè)置為10。public static String hashPassword(String textPassword){        String salt = BCrypt.gensalt(workload);        String hashPassword = BCrypt.hashpw(textPassword, salt);        return hashPassword;}當(dāng)執(zhí)行 hashpw() 函數(shù)時(shí),無效的鹽版本錯(cuò)誤會(huì)被拋出到異常中。
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊

這是 Bcrypt 庫始終需要格式化鹽。根據(jù)您的明文大小,如果小于 BCRYPT_SALT_LEN,rnd 的其余部分用隨機(jī)字節(jié)填充,其余部分與庫中一樣。


public static String gensalt(int log_rounds, SecureRandom random, String plaintextSalt) {


? ? byte[] plaintextByte = plaintextSalt.getBytes();

? ? byte rnd[] = new byte[BCRYPT_SALT_LEN];


? ? //Use all of the string if size >= of the reqired rnd size

? ? if (plaintextByte.length >= BCRYPT_SALT_LEN) {

? ? ? ? System.arraycopy(plaintextByte, 0, rnd, 0, rnd.length);


? ? } else {

? ? ? ? //copy all of the string byte array

? ? ? ? System.arraycopy(plaintextByte, 0, rnd, 0, plaintextByte.length);


? ? ? ? //fill the rest with random

? ? ? ? byte[] tempArray = new byte[BCRYPT_SALT_LEN - plaintextByte];

? ? ? ? random.nextBytes(tempArray);

? ? ? ? System.arraycopy(tempArray, 0, rnd, plaintextByte.length, temp.length);

? ? }


? ? StringBuffer rs = new StringBuffer();


? ? rs.append("$2a$");

? ? if (log_rounds < 10)

? ? ? ? rs.append("0");

? ? if (log_rounds > 30) {

? ? ? ? throw new IllegalArgumentException(

? ? ? ? ? ? ? ? "log_rounds exceeds maximum (30)");

? ? }

? ? rs.append(Integer.toString(log_rounds));

? ? rs.append("$");

? ? rs.append(encode_base64(rnd, rnd.length));

? ? return rs.toString();


}


查看完整回答
反對 回復(fù) 2023-06-21
  • 1 回答
  • 0 關(guān)注
  • 197 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號