2012-08-01 85 views
3

最近在我的項目中,我用我們的分貝重複搜索lucene它是完美的工作。 但現在需要加密lucene索引,我被要求尋找由lucene本身提供的加密設施,而不是使用外部庫。lucene加密設施

我剛剛找到了LUCENE-2228 AES Encrypted Directory並製作了小的POC。 問題是,當我這樣做重新索引我收到以下錯誤:

java.lang.RuntimeException: File already Exists 
    at org.apache.lucene.util.AESWriter.<init>(AESWriter.java:117) 
    at org.apache.lucene.store.AESDirectory$AESIndexOutput.<init> 
     (AESDirectory.java:187) 
    at org.apache.lucene.store.AESDirectory.createOutput(AESDirectory.java:72) 
    at org.apache.lucene.index.SegmentInfos.finishCommit(SegmentInfos.java:939) 
    at org.apache.lucene.index.IndexWriter.finishCommit(IndexWriter.java:3539) 
    at org.apache.lucene.index.IndexWriter.commitInternal(IndexWriter.java:3529) 
    at org.apache.lucene.index.IndexWriter.closeInternal(IndexWriter.java:1879) 
    at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:1822) 
    at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:1786) 
    at org.apache.lucene.test.indexing.main(indexing.java:45) 

這裏是我的代碼

public class indexing 
{ 
    private static final byte[] KEY = 
     new byte[] { 'T', 'h', 'e', 'B', 'e', 's', 't', 
'S', 'e', 'c', 'r','e', 't', 'K', 'e', 'y' }; 
    public static void main(String[] args) throws Exception 
    { 

     Directory INDEX_DIR = new AESDirectory(new File("index1"),KEY); 

     Connection conn=null; 

     SnowballAnalyzer analyzer=new SnowballAnalyzer(Version.LUCENE_30,"English"); 
     try 
     { 
      Class.forName("com.mysql.jdbc.Driver").newInstance(); 
      conn = DriverManager.getConnection("jdbc:mysql:///lucene", "abcd", "abcd"); 
      IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_34, analyzer); 
      IndexWriter writer = new IndexWriter(INDEX_DIR, config); 
      writer.deleteAll(); 
      //writer.flush(); 
      System.out.println("Indexing to directory '" + INDEX_DIR + "'..."); 
      long starttime=System.currentTimeMillis(); 
      indexDocs(writer, conn); 
      writer.optimize(); 
      writer.close(); 
      long endtime=System.currentTimeMillis(); 
      long timetaken=TimeUnit.MILLISECONDS.convert(endtime - starttime,TimeUnit.MILLISECONDS); 
      System.out.println("Time taken to do indexing is "+timetaken+"ms"); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
    static void indexDocs(IndexWriter writer, Connection conn) throws Exception 
    { 
     //String sql = "select qid,question from tblquestions"; 
     String sql = "select qid,question from tblquestions"; 
     Statement stmt = conn.createStatement(); 
     stmt.setFetchSize(Integer.MIN_VALUE); 
     ResultSet rs = stmt.executeQuery(sql); 
     Integer count = 0; 
     while (rs.next()) 
     { 
      count ++; 
      Document d = new Document(); 
      d.add(new Field("qid", rs.getString("qid"), Field.Store.YES, Field.Index.NOT_ANALYZED)); 
      d.add(new Field("question", rs.getString("question"), Field.Store.YES, Field.Index.ANALYZED)); 
      writer.addDocument(d); 
     } 
     System.out.println("count: " + count); 
    } 
} 

任何人可以幫助我解決這個問題。 或 給出有關lucene索引加密的一些想法。

+0

您正在使用哪種版本的lucene?你有沒有得到AESDirectory的工作? – Rocky 2012-12-20 07:36:33

+1

你有沒有考慮加密你的整個文件系統? – 2013-01-20 09:42:35

+0

或者至少在Lucene索引目錄中安裝一個加密的FS /容器/覆蓋層? – 2014-07-18 10:29:23

回答

0

這個補丁是針對版本3.1的,看起來您使用的是其他版本的Lucene。選擇下列選項之一,直到你的版本補丁出來(或寫自己的補丁!)

  1. 切換到Lucene的3.1

  2. 使用Windows NTFS加密。應該是安全的,除非未經授權的人知道如何以創建索引的用戶身份登錄。

  3. 繼續使用TrueCrypt或其他外部加密。這應該是非常安全的,但它需要安裝TrueCrypt和管理權限來安裝加密驅動器。