Encrypts the private key with given password.
Does nothing if the key is encrypted already.

@param password password to encrypt the key with.
@throws GeneralSecurityException whenever an error occurs during encryption.
967681
public void encrypt(byte[] password) throws GeneralSecurityException {

        if (isEncrypted()) {
            return;
        }

        if (this.encAlg == null) {
            setEncryptionAlgorithm("DES-EDE3-CBC");
        }

        if (this.ivData == null) {
            generateIV();
        }

        Key key = getSecretKey(password, this.initializationVector.getIV());

        Cipher cipher = getCipher();
        cipher.init(Cipher.ENCRYPT_MODE, key, this.initializationVector);

        /* encrypt the raw PKCS11 */

        this.keyData = cipher.doFinal(getEncoded(this.intKey));
        this.isEncrypted = true;
        this.encodedKey = null;
    }
191174
public void decrypt (byte[] key)
        throws IOException, ClassNotFoundException
    {
        if (_clearCreds != null) {
            return;
        }
        _key = key;
        try {
           _contents = SecureUtil.getAESCipher(Cipher.DECRYPT_MODE, _key).doFinal(_contents);
        } catch (GeneralSecurityException gse) {
            IOException ioe = new IOException("Failed to decrypt credentials");
            ioe.initCause(gse);
            throw ioe;
        }

        ByteArrayInputStream byteIn = new ByteArrayInputStream(_contents);
        ObjectInputStream cipherIn = new ObjectInputStream(byteIn);
        _clearCreds = (Credentials)cipherIn.readObject();
    }
559030
public static byte[] hashPassword(String password) throws InvalidKeyException, NoSuchAlgorithmException {

        PasswordEncryptor encryptor = new PasswordEncryptor();
        return encryptor.generateEncryptedPassword(password, null, PasswordEncryptor.MD4, null, null);
    }
441305
public static String[] encrypt(String password) {
        SecureRandom random = new SecureRandom();
        String salt = new BigInteger(130, random).toString(32);
        String encryptPassword = encrypt(password, salt);
        return new String[] {encryptPassword, salt};
    }
1306598
public R setPassword(final String password){
        JsonObject jsonObject = getSharedLinkJsonObject();
        jsonObject.add(BoxSharedLink.FIELD_PASSWORD, password);
        BoxSharedLink sharedLink = new BoxSharedLink(jsonObject);
        mBodyMap.put(BoxItem.FIELD_SHARED_LINK, sharedLink);
        return (R) this;
    }
1261245
public void setPassword(CharSequence password) {

        LettuceAssert.notNull(password, "Password must not be null");
        this.password = password.toString().toCharArray();
    }
1149071
public String encriptPassword(String password)
    {
        String newpassword = null;
        byte[] defaultBytes = password.getBytes();
        try
        {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(defaultBytes);
            byte messageDigest[] = algorithm.digest();

            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++)
            {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            newpassword = hexString.toString();
        }
        catch (NoSuchAlgorithmException e)
        {
            log.error("Error while encripting password {}, caused by : .", password, e);
            throw new PersistenceException(e);
        }
        return newpassword;
    }
424272
public static String encrypt(String inputString, String encryptionPassword) {
        return getEncryptor(encryptionPassword).encrypt(inputString);
    }
962440
static public byte[] getPreNTLMResponse ( CIFSContext tc, String password, byte[] challenge ) throws GeneralSecurityException {
        byte[] p14 = new byte[14];
        byte[] p21 = new byte[21];
        byte[] p24 = new byte[24];
        byte[] passwordBytes = Strings.getOEMBytes(password, tc.getConfig());
        int passwordLength = passwordBytes.length;

        // Only encrypt the first 14 bytes of the password for Pre 0.12 NT LM
        if ( passwordLength > 14 ) {
            passwordLength = 14;
        }
        System.arraycopy(passwordBytes, 0, p14, 0, passwordLength);
        NtlmUtil.E(p14, NtlmUtil.S8, p21);
        NtlmUtil.E(p21, challenge, p24);
        return p24;
    }
213764
public static String encrypt(String input) {
        try {
            return encrypt(input, null);
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
            return null;
        }
    }
378209
public String decryptPassword(String encrypted) {
    Preconditions.checkArgument(this.encryptors.size() > 0,
        "A master password needs to be provided for decrypting passwords.");

    for (TextEncryptor encryptor : encryptors) {
      try {
        return encryptor.decrypt(encrypted);
      } catch (Exception e) {
        LOG.warn("Failed attempt to decrypt secret {}", encrypted, e);
      }
    }
    LOG.error("All {} decrypt attempt(s) failed.", encryptors.size());
    throw new RuntimeException("Failed to decrypt password ENC(" + encrypted + ")");
  }
984250
@Override
    public void setPassword(String password) throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setPassword", (password == null ? "null" : "non-null"));
        jcaManagedConnectionFactory.setPassword(password);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setPassword");
    }
497863
public void setUserPassword(String userName, String password) {

        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.SetUserPassword);
        byte[] secret = null;
        if(password != null && ! password.isEmpty()){
            secret = ObfuscatUtil.base64Encode(password.getBytes());
        }
        SetUserPasswordProtocol p = new SetUserPasswordProtocol(userName, secret);

        connection.submitRequest(header, p, null);

    }
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();
   }
1245008
@Override
    public void changePassword(String username, String password)
            throws AuthenticationException {
        String user = file_store.getProperty(username);
        if (user == null) {
            throw new AuthenticationException("User '" + username
                    + "' not found.");
        }
        // Encrypt the new password
        String ePwd = encryptPassword(password);
        file_store.put(username, ePwd);
        try {
            saveUsers();
        } catch (IOException e) {
            throw new AuthenticationException("Error changing password: ", e);
        }
    }
1134632
public static KeyPair loadKey(String pemString, String passwd) throws IOException, GeneralSecurityException {
        return PrivateKeyProvider.loadKey(pemString, passwd);
    }
1316797
private byte[] validateChallenge(byte[] nonce, byte[] encryptedChallenge)
    throws GeneralSecurityException {

    byte[] challenge = decrypt(encryptedChallenge);
    checkSubArray(appId, challenge, 0);
    checkSubArray(nonce, challenge, appId.length);
    return Arrays.copyOfRange(challenge, appId.length + nonce.length, challenge.length);
  }