LTTPP / Eemory

An Eclipse plug-in aimed at integrating Evernote within the Eclipse IDE
MIT License
7 stars 0 forks source link

Store master password in Eclipse Secure Storage #90

Open liujianuuei opened 8 years ago

liujianuuei commented 8 years ago

Store master password in Eclipse Secure Storage. 1 2

liujianuuei commented 7 years ago

Ref:

/*    */ 
/*    */ import java.io.IOException;
/*    */ import org.eclipse.equinox.security.storage.EncodingUtils;
/*    */ import org.eclipse.equinox.security.storage.ISecurePreferences;
/*    */ import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
/*    */ import org.eclipse.equinox.security.storage.StorageException;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class EeSecureStore
/*    */   implements ICredentialsStore
/*    */ {
/*    */   private static final String ID_PLUGIN = "com.lttpp.eemory";
/*    */   private final String url;
/* 20 */   public static final ICredentialsStore INSTANCE = new EeSecureStore(
/* 21 */     "default");
/*    */   
/*    */   private EeSecureStore(String url) {
/* 24 */     this.url = url;
/*    */   }
/*    */   
/*    */   public void clear() {
/* 28 */     getSecurePreferences().removeNode();
/*    */   }
/*    */   
/*    */   public void flush() throws IOException {
/* 32 */     getSecurePreferences().flush();
/*    */   }
/*    */   
/*    */   public String get(String key, String def) throws StorageException {
/* 36 */     return getSecurePreferences().get(key, def);
/*    */   }
/*    */   
/*    */   public byte[] getByteArray(String key, byte[] def) throws StorageException {
/* 40 */     return getSecurePreferences().getByteArray(key, def);
/*    */   }
/*    */   
/*    */   private ISecurePreferences getSecurePreferences() {
/* 44 */     ISecurePreferences securePreferences = 
/* 45 */       SecurePreferencesFactory.getDefault().node("com.lttpp.eemory");
/* 46 */     securePreferences = securePreferences.node(
/* 47 */       EncodingUtils.encodeSlashes(getUrl()));
/* 48 */     return securePreferences;
/*    */   }
/*    */   
/*    */   public String getUrl() {
/* 52 */     return url;
/*    */   }
/*    */   
/*    */   public String[] keys() {
/* 56 */     return getSecurePreferences().keys();
/*    */   }
/*    */   
/*    */   public void put(String key, String value, boolean encrypt) throws StorageException
/*    */   {
/* 61 */     getSecurePreferences().put(key, value, encrypt);
/*    */   }
/*    */   
/*    */   public void putByteArray(String key, byte[] value, boolean encrypt) throws StorageException
/*    */   {
/* 66 */     getSecurePreferences().putByteArray(key, value, encrypt);
/*    */   }
/*    */   
/*    */   public void remove(String key) {
/* 70 */     getSecurePreferences().remove(key);
/*    */   }
/*    */   
/*    */   public void copyTo(ICredentialsStore target) throws StorageException {
/* 74 */     ISecurePreferences preferences = getSecurePreferences();
/* 75 */     String[] arrayOfString; int j = (arrayOfString = preferences.keys()).length; for (int i = 0; i < j; i++) { String key = arrayOfString[i];
/* 76 */       target.put(key, preferences.get(key, null), 
/* 77 */         preferences.isEncrypted(key));
/*    */     }
/*    */   }
/*    */ }
liujianuuei commented 7 years ago

P4SecureStore.txt