code: public static byte[] encryptPrivateKeyWithPassword(final PrivateKey privateKey,
  		final String password) throws NoSuchAlgorithmException, InvalidKeySpecException,
  		NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException,
  		IllegalBlockSizeException, BadPaddingException, InvalidParameterSpecException, IOException
  	{
  		final byte[] privateKeyEncoded = privateKey.getEncoded();
  
  		final SecureRandom random = new SecureRandom();
  		final byte[] salt = new byte[8];
  		random.nextBytes(salt);
  
  		final AlgorithmParameterSpec algorithmParameterSpec = AlgorithmParameterSpecFactory
  			.newPBEParameterSpec(salt, 20);
  
  		final SecretKey secretKey = SecretKeyFactoryExtensions.newSecretKey(password.toCharArray(),
  			CompoundAlgorithm.PBE_WITH_SHA1_AND_DES_EDE.getAlgorithm());
  
  		final Cipher pbeCipher = Cipher
  			.getInstance(CompoundAlgorithm.PBE_WITH_SHA1_AND_DES_EDE.getAlgorithm());
  
  		pbeCipher.init(Cipher.ENCRYPT_MODE, secretKey, algorithmParameterSpec);
  
  		final byte[] ciphertext = pbeCipher.doFinal(privateKeyEncoded);
  
  		final AlgorithmParameters algparms = AlgorithmParameters
  			.getInstance(CompoundAlgorithm.PBE_WITH_SHA1_AND_DES_EDE.getAlgorithm());
  		algparms.init(algorithmParameterSpec);
  		final EncryptedPrivateKeyInfo encinfo = new EncryptedPrivateKeyInfo(algparms, ciphertext);
  
  		return encinfo.getEncoded();
  	}
docs: Encrypt the given {@link PrivateKey} with the given password and return the resulted byte
  array.
  
  @param privateKey
  the private key to encrypt
  @param password
  the password
  @return the byte[]
  @throws NoSuchAlgorithmException
  is thrown if instantiation of the SecretKeyFactory object fails.
  @throws InvalidKeySpecException
  is thrown if generation of the SecretKey object fails.
  @throws NoSuchPaddingException
  the no such padding exception
  @throws InvalidKeyException
  is thrown if initialization of the cipher object fails
  @throws InvalidAlgorithmParameterException
  is thrown if initialization of the cypher object fails.
  @throws IllegalBlockSizeException
  the illegal block size exception
  @throws BadPaddingException
  the bad padding exception
  @throws InvalidParameterSpecException
  the invalid parameter spec exception
  @throws IOException
  Signals that an I/O exception has occurred.