Openfire是通過org.jivesoftware.util.Blowfish.java實現的加密。
使用Blowfish的encryptString(String
password)和decryptString(String encryptedString)兩個方法執行加解密。
可new Blowfish(String passwordKey)需要passwordKey,上哪裡找?
原來在openfire的資料庫中有表ofproperty,其中就有passwordKey的值,這是openfire安裝時自動產生的。
openfire每次自動產生資料庫的時候這個屬性都是不同的,所以如果資料庫變化了,原來的使用者資訊匯入是沒有用的。
可以獨立使用org.jivesoftware.util.Blowfish.java進行加解密操作。
將org.jivesoftware.util.Blowfish.java拷貝到自己的項目中來,範例程式碼如下:
public String getEncryPWD(String noEncryPWD) {String resultPWD = null;String passWordKey = null; //passwordKey,從openfire資料庫中讀取/* * 下面這段是從ofProperty表中查詢得到passwordKey的值。OfProperty ofProperty = ofPropertyMapper.selectByPrimaryKey("passwordKey");if (ofProperty != null) {passWordKey = ofProperty.getPropvalue();} */Blowfish blowFish = new Blowfish(passWordKey); //根據加密key初始化passWordKey = blowFish.encryptString(noEncryPWD); //加密return resultPWD; //返回加密後的結果}