net.sf.hermesftp.utils
Class SecurityUtil

java.lang.Object
  extended by net.sf.hermesftp.utils.SecurityUtil

public final class SecurityUtil
extends java.lang.Object

Security related utility methods.

Author:
Lars Behnke

Method Summary
static boolean checkPassword(java.lang.String passwordHash, java.lang.String password)
          Checks the validity of the password password based on a given hash code.
static javax.net.ssl.SSLContext createSslContext(java.lang.String keyStoreFile, char[] keyStorePassword)
          Create the security context required for SSL communication.
static java.lang.String digestPassword(java.lang.String password, java.lang.String algorithm)
          Calculates based on the passed parameters an hash code and returns its BASE64 representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

digestPassword

public static java.lang.String digestPassword(java.lang.String password,
                                              java.lang.String algorithm)
                                       throws java.security.NoSuchAlgorithmException
Calculates based on the passed parameters an hash code and returns its BASE64 representation. The used algorithm is prepended.

Parameters:
password - The password to encode.
algorithm - The algorithm to use (MD5 e.g.)
Returns:
The encoded password as string.
Throws:
java.security.NoSuchAlgorithmException - Passed algorithm is not supported.

checkPassword

public static boolean checkPassword(java.lang.String passwordHash,
                                    java.lang.String password)
                             throws java.security.NoSuchAlgorithmException
Checks the validity of the password password based on a given hash code. The hash code to check against contains the used algorithm has prefix. Example: {MD5}Cwz8B/yoHJVquRgdhXb0qA==.

Parameters:
passwordHash - The hash code to check against.
password - The password to check.
Returns:
True, if password is valid.
Throws:
java.security.NoSuchAlgorithmException - Algorithm (from hash prefix) is not supported.

createSslContext

public static javax.net.ssl.SSLContext createSslContext(java.lang.String keyStoreFile,
                                                        char[] keyStorePassword)
                                                 throws FtpConfigException
Create the security context required for SSL communication.

Parameters:
keyStoreFile - The name of the keystore file.
keyStorePassword - The password for the keystore.
Returns:
The context.
Throws:
FtpConfigException - Thrown on error in configuration.


Copyright © 2005-2007 Lars Behnke. All Rights Reserved.