Exemplo n.º 1
0
 private boolean savePassword(String password, IPreferencesContainer container) {
   byte[] data = winencrypt(password.getBytes());
   if (data == null) { // this is bad. Something wrong with OS or JNI.
     StorageException e =
         new StorageException(
             StorageException.ENCRYPTION_ERROR, WinCryptoMessages.encryptPasswordFailed);
     AuthPlugin.getDefault().logError(WinCryptoMessages.encryptPasswordFailed, e);
     return false;
   }
   String encodedEncryptyedPassword = Base64.encode(data);
   ISecurePreferences node = container.getPreferences().node(WIN_PROVIDER_NODE);
   try {
     node.put(
         PASSWORD_KEY,
         encodedEncryptyedPassword,
         false); // note we don't recursively try to encrypt
   } catch (StorageException e) { // should never happen in this scenario
     AuthPlugin.getDefault().logError(SecAuthMessages.errorOnSave, e);
     return false;
   }
   try {
     node.flush(); // save right away
   } catch (IOException e) {
     AuthPlugin.getDefault().logError(SecAuthMessages.errorOnSave, e);
     return false;
   }
   return true;
 }
Exemplo n.º 2
0
 private byte[] getEncryptedPassword(IPreferencesContainer container) {
   ISecurePreferences node = container.getPreferences().node(WIN_PROVIDER_NODE);
   String passwordHint;
   try {
     passwordHint = node.get(PASSWORD_KEY, null);
   } catch (StorageException e) { // should never happen in this scenario
     AuthPlugin.getDefault().logError(WinCryptoMessages.decryptPasswordFailed, e);
     return null;
   }
   if (passwordHint == null) return null;
   return Base64.decode(passwordHint);
 }