protected static byte[] getKeyFromPassphrase(String passphrase, byte[] iv,
			int keySize) throws IOException {
		try {
			byte[] passphraseBytes;

			try {
				passphraseBytes = passphrase == null ? new byte[0] : passphrase
						.getBytes("UTF-8");
			} catch (UnsupportedEncodingException e) {
				throw new IOException(
						"Mandatory US-ASCII character encoding is not supported by the VM");
			}

			/*
			 * hash is MD5 h(0) <- hash(passphrase, iv); h(n) <- hash(h(n-1),
			 * passphrase, iv); key <- (h(0),...,h(n))[0,..,key.length];
			 */
			Digest hash = (Digest) ComponentManager.getInstance()
					.supportedDigests().getInstance("MD5");

			byte[] key = new byte[keySize];

			int hashesSize = keySize & 0xfffffff0;

			if ((keySize & 0xf) != 0) {
				hashesSize += MD5_HASH_BYTES;
			}

			byte[] hashes = new byte[hashesSize];

			byte[] previous;

			for (int index = 0; (index + MD5_HASH_BYTES) <= hashes.length; hash
					.putBytes(previous, 0, previous.length)) {
				hash.putBytes(passphraseBytes, 0, passphraseBytes.length);
				hash.putBytes(iv, 0, 8);
				previous = hash.doFinal();
				System.arraycopy(previous, 0, hashes, index, previous.length);
				index += previous.length;
			}

			System.arraycopy(hashes, 0, key, 0, key.length);

			return key;
		} catch (SshException e) {
			throw new SshIOException(e);
		}
	}
protected static byte [ ] getKeyFromPassphrase ( String passphrase , byte [ ] iv , int keySize ) throws IOException { try { byte [ ] passphraseBytes ; try { passphraseBytes = passphrase == null ? new byte [ 0 ] : passphrase . getBytes ( "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { throw new IOException ( "Mandatory US-ASCII character encoding is not supported by the VM" ) ; } Digest hash = ( Digest ) ComponentManager . getInstance ( ) . supportedDigests ( ) . getInstance ( "MD5" ) ; byte [ ] key = new byte [ keySize ] ; int hashesSize = keySize & 0xfffffff0 ; if ( ( keySize & 0xf ) != 0 ) { hashesSize += MD5_HASH_BYTES ; } byte [ ] hashes = new byte [ hashesSize ] ; byte [ ] previous ; for ( int index = 0 ; ( index + MD5_HASH_BYTES ) <= hashes . length ; hash . putBytes ( previous , 0 , previous . length ) ) { hash . putBytes ( passphraseBytes , 0 , passphraseBytes . length ) ; hash . putBytes ( iv , 0 , 8 ) ; previous = hash . doFinal ( ) ; System . arraycopy ( previous , 0 , hashes , index , previous . length ) ; index += previous . length ; } System . arraycopy ( hashes , 0 , key , 0 , key . length ) ; return key ; } catch ( SshException e ) { throw new SshIOException ( e ) ; } }
@param passphrase
@param iv
@param keySize

@return byte[]