我在申請認證時使用shiro。我使用哈希密碼與鹽和我將它們存儲在我的數據庫是這樣的:如何從數據庫庫存和使用shiro的鹽
private User createUserWithHashedPassword(String inName, String inFirstName, String inLastName, String inPassword){
ByteSource salt = randomNumberGenerator.nextBytes(32);
byte[] byteTabSalt = salt.getBytes();
String strSalt = byteArrayToHexString(byteTabSalt);
String hashedPasswordBase64 = new Sha256Hash(inPassword, salt, 1024).toBase64();
return new User(inName,inFirstName,inLastName,hashedPasswordBase64,strSalt);
}
我店將鹽與在我的數據庫的String。現在在我的領域,我想從數據庫中取回數據,我爲此使用了一個transactionnal服務。但我的鹽是一個強大的,所以我希望它與靜態方法回頭爲ByteSource類型:
ByteSource byteSourceSalt = Util.bytes(salt); //where the salt is a String
但是當我創造我SaltedAuthenticationInfo不權威性。
我想我的問題是從我的轉換方法:
private String byteArrayToHexString(byte[] bArray){
StringBuffer buffer = new StringBuffer();
for(byte b : bArray) {
buffer.append(Integer.toHexString(b));
buffer.append(" ");
}
return buffer.toString().toUpperCase();
}
感謝您的幫助。
如何獲得由shiro生成的公共salt auto以便將其存儲到db中的分隔列 – thoitbk