Encodes/obfuscates a password. Although this does not prevent actual
hacking of password, it does remove the obvious threats of having
passwords stored as clear text.

@param password
@return a String containing the encoded password
431334
public static String encodePassword(final String password) {
        if (password == null) {
            return null;
        }
        return encodePassword(password.toCharArray());
    }
792003
public EncryptionKey loadKeyUsingPassword(String password) {
        if (password == null || password.equals("")) {
            throw new IllegalArgumentException("password is required to be a non-null/non-empty " +
                    "string");
        }
        KeyData data = this.storage.getEncryptionKeyData();
        if (data == null || !validateEncryptionKeyData(data)) {
            return null;
        }

        EncryptionKey dpk = null;
        SecretKey aesKey = null;
        try {
            aesKey = pbkdf2DerivedKeyForPassword(password, data.getSalt(), data.iterations,
                    ENCRYPTION_KEYCHAIN_AES_KEY_SIZE);
            byte[] dpkBytes = DPKEncryptionUtil.decryptAES(aesKey, data.getIv(), data
                    .getEncryptedDPK());
            dpk = new EncryptionKey(dpkBytes);
        } catch (NoSuchAlgorithmException e) {
            throw new DPKException("Failed to decrypt DPK", e);
        } catch (InvalidKeySpecException e) {
            throw new DPKException("Failed to decrypt DPK", e);
        } catch (IllegalBlockSizeException e) {
            throw new DPKException("Failed to decrypt DPK", e);
        } catch (InvalidKeyException e) {
            throw new DPKException("Failed to decrypt DPK", e);
        } catch (BadPaddingException e) {
            throw new DPKException("Failed to decrypt DPK", e);
        } catch (InvalidAlgorithmParameterException e) {
            throw new DPKException("Failed to decrypt DPK", e);
        } catch (NoSuchPaddingException e) {
            throw new DPKException("Failed to decrypt DPK", e);
        }

        return dpk;
    }
665276
public String encryptString(String credentials) {
        byte[] credentialBytes = checkNotNull(credentials, "credentials").getBytes(Charsets.UTF_8);
        return encryptBytes(credentialBytes);
    }
1108405
function encode(password, cb) {
  var secret_key = conf.secret_key
    , iterations = conf.pbkdf2_iterations
    , keylen = conf.pbkdf2_keylen;

  crypto.pbkdf2(password, secret_key, iterations, keylen, function(err, derivedKey) {
    var str;

    if(err) {
      cb(err);
    } else {
      str = new Buffer(derivedKey).toString('base64');
      cb(null, str);
    }
  });
}
928958
public static String obfuscate(String s)
    {
        StringBuffer buf = new StringBuffer();
        byte[] b = s.getBytes();
        
        synchronized(buf)
        {
            buf.append("OBF:");
            for (int i=0;i<b.length;i++)
            {
                byte b1 = b[i];
                byte b2 = b[s.length()-(i+1)];
                int i1= (int)b1+(int)b2+127;
                int i2= (int)b1-(int)b2+127;
                int i0=i1*256+i2;
                String x=Integer.toString(i0,36);

                switch(x.length())
                {
                  case 1:buf.append('0');
                  case 2:buf.append('0');
                  case 3:buf.append('0');
                  default:buf.append(x);
                }
            }
            return buf.toString();
        }
    }
618535
public void enpass(final String password, final OutputStream os) throws IOException {
		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		byte[] bytes = password.getBytes();
		if(this.getClass().getSimpleName().startsWith("base64")) { // don't expose randomization
			dos.write(bytes);
		} else {
			
			Random r = new SecureRandom();
			int start = 0;
			byte b;
			for(int i=0;i<3;++i) {
				dos.writeByte(b=(byte)r.nextInt());
				start+=Math.abs(b);
			}
			start%=0x7;
			for(int i=0;i<start;++i) {
				dos.writeByte(r.nextInt());
			}
			dos.writeInt((int)System.currentTimeMillis());
			int minlength = Math.min(0x9,bytes.length);
			dos.writeByte(minlength); // expect truncation
			if(bytes.length<0x9) {
				for(int i=0;i<bytes.length;++i) {
					dos.writeByte(r.nextInt());
					dos.writeByte(bytes[i]);
				}
				// make sure it's long enough
				for(int i=bytes.length;i<0x9;++i) {
					dos.writeByte(r.nextInt());
				}
			} else {
				dos.write(bytes);
			}
		}
		
		// 7/21/2016 jg add AES Encryption to the mix
		exec(new AESExec() {
			@Override
			public void exec(AES aes) throws IOException {
				CipherInputStream cis = aes.inputStream(new ByteArrayInputStream(baos.toByteArray()), true);
				try {
					encode(cis,os);
				} finally {
					os.flush();
					cis.close();
				}
			}
		});
		synchronized(ENC) {
		}
	}
556299
public static char[] decrypt(char[] password)
	{
		if(password == null || password.length == 0)
			return null;
		

		String passwordString = String.valueOf(password);
		try
		{
			byte[] decrypted = null;
			if (passwordString.startsWith("encrypted(")
					&& passwordString.endsWith(")"))
			{
				passwordString = passwordString.substring(10,
							passwordString.length() - 1);
			}
			
			SecretKeySpec key = new SecretKeySpec(init, "Blowfish");
			Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE);
			cipher.init(Cipher.DECRYPT_MODE, key);
			decrypted = cipher.doFinal(hexStringToByteArray(passwordString));
			

			return  new String(decrypted, Charset.forName("UTF8")).toCharArray();
		
		}
		catch (Exception e)
		{
			throw new SecurityException(
					"Unable to decrypt password. Check that the password has been encrypted.", e);
		}
	}
1322269
protected String encodePassword(String password)
   {
      StringBuilder result = new StringBuilder();
      if (password != null)
      {
         for (int i = 0; i < password.length(); i++)
         {
            int c = password.charAt(i);
            c ^= 0xdfaa;
            result.append(Integer.toHexString(c));
         }
      }
      return result.toString();
   }
1340307
public static String encodeAuthAmqPlain(String username, char[] password) {
        Logger logger = LoggerFactory.getLogger(SERVICE_AMQP_PROXY_LOGGER);
        if (logger.isDebugEnabled()) {
            logger.debug(CLASS_NAME + ".encodeAuthAmqPlain(): Username - " + username);
        }

        int size =  1  +                   // LOGIN.length
                    5  +                   // LOGIN
                    1  +                   // type-id -- 'S' for LongString
                    4  +                   // username's length
                    username.length() +    // username
                    1  +                   // PASSWORD.length
                    8  +                   // PASSWORD
                    1  +                   // type-id -- 'S' for LongString
                    4  +                   // password's length
                    password.length;       // password
                    
        ByteBuffer buffer = ByteBuffer.allocate(size);

        putShortString(buffer, "LOGIN");
        putType(buffer, AmqpType.LONGSTRING);
        putLongString(buffer, username);

        putShortString(buffer, "PASSWORD");
        putType(buffer, AmqpType.LONGSTRING);
        putLongString(buffer, new String(password)); // ### TODO: Use char[] directly
        buffer.flip();
        
        // Nulling out the password for security. 
        Arrays.fill(password, '\0');

        int len = buffer.remaining();
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < len; i++)
        {
            builder.append((char)(buffer.get() & 0xff)); 

        }
        String s = builder.toString();
        return s;
    }
143849
def _encrypt_password(self, password):
        
        if self.encryption_mode.lower() == 'crypt':
            return self._crypt_password(password)
        elif self.encryption_mode.lower() == 'md5':
            return self._md5_password(password)
        elif self.encryption_mode.lower() == 'md5-base':
            return self._md5_base_password(password)
        else:
            raise UnknownEncryptionMode(self.encryption_mode)
553954
private void writePassword(String resource, String password) throws IOException {
    String[] resourceParts = resource.split("\\$MD5\\$");
    if (resourceParts.length == 1) {
      // Write in clean
      outputStream.write(password);
    } else {
      outputStream.write("$MD5$" + SanePasswordEncoder.derivePassword(resourceParts[1], password));
    }
  }
1261457
public static String encrypt(String password, String salt) {
        String saltPassword = password + salt;
        return DigestUtils.sha256Hex(saltPassword.getBytes());
    }
507317
public static String encrypt(String cleartext) {
		if (cleartext != null) {
			byte[] result = doFinal(Base64.decode(getBase64Key(), Base64.DEFAULT), Cipher.ENCRYPT_MODE,
				cleartext.getBytes());
			return Base64.encodeToString(result, Base64.DEFAULT);
		}
		return null;
	}
1087985
def encode(password)
      primary = ::Digest::MD5.new
      primary << password
      primary << prefix
      primary << @salt

      md5_t = ::Digest::MD5.digest("#{password}#{@salt}#{password}")

      l = password.length
      while l > 0 do
        slice_size = ( l > DIGEST_LENGTH ) ? DIGEST_LENGTH : l
        primary << md5_t[0, slice_size]
        l -= DIGEST_LENGTH
      end

      # weirdness
      l = password.length
      while l != 0
        case (l & 1)
        when 1
          primary << 0.chr
        when 0
          primary << password[0,1]
        end
        l >>= 1
      end

      pd = primary.digest

      encoded_password = "#{prefix}#{@salt}$"

      # apr_md5_encode has this comment about a 60Mhz Pentium above this loop.
      1000.times do |x|
        ctx = ::Digest::MD5.new
        ctx << (( ( x & 1 ) == 1 ) ? password : pd[0,DIGEST_LENGTH])
        (ctx << @salt) unless ( x % 3 ) == 0
        (ctx << password) unless ( x % 7 ) == 0
        ctx << (( ( x & 1 ) == 0 ) ? password : pd[0,DIGEST_LENGTH])
        pd = ctx.digest
      end


      pd = pd.bytes.to_a

      l = (pd[ 0]<<16) | (pd[ 6]<<8) | pd[12]
      encoded_password << to_64(l, 4)

      l = (pd[ 1]<<16) | (pd[ 7]<<8) | pd[13]
      encoded_password << to_64(l, 4)

      l = (pd[ 2]<<16) | (pd[ 8]<<8) | pd[14]
      encoded_password << to_64(l, 4)

      l = (pd[ 3]<<16) | (pd[ 9]<<8) | pd[15]
      encoded_password << to_64(l, 4)

      l = (pd[ 4]<<16) | (pd[10]<<8) | pd[ 5]
      encoded_password << to_64(l, 4)
      encoded_password << to_64(pd[11],2)

      return encoded_password
    end
995297
public String getPassword()
    {
    	if ((password != null) && (password.length() > 0))
    		return password;	// External override
        char[] rgchPassword = passwordField.getPassword();
        return new String(rgchPassword);
    }
666540
public Proxy setSocksPassword(String password) {
    verifyProxyTypeCompatibility(ProxyType.MANUAL);
    this.proxyType = ProxyType.MANUAL;
    this.socksPassword = password;
    return this;
  }
452259
private static String encodeAuthPlain(String username, char[] password) {
        // PLAIN mechanism encoding - NUL + username + NUL + password
        int size = username.length() + password.length + 2;
        ByteBuffer buffer = ByteBuffer.allocate(size);
        buffer.put((byte)0);
        buffer.put(username.getBytes());
        buffer.put((byte)0);
        buffer.put(new String(password).getBytes());
        
        buffer.flip();
        
        // Nulling out the password for security. 
        Arrays.fill(password, '\0');

        int len = buffer.remaining();
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < len; i++)
        {
            builder.append((char)(buffer.get() & 0xff)); 

        }
        String s = builder.toString();
        return s;

    }