<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Canmanjoe</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Canmanjoe"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Canmanjoe"/>
		<updated>2026-04-23T21:07:55Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SSL_Best_Practices&amp;diff=57141</id>
		<title>SSL Best Practices</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SSL_Best_Practices&amp;diff=57141"/>
				<updated>2009-03-22T10:21:13Z</updated>
		
		<summary type="html">&lt;p&gt;Canmanjoe: /* How SSL is implemented in J2EE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Status ==&lt;br /&gt;
Draft&lt;br /&gt;
&lt;br /&gt;
==What is SSL==&lt;br /&gt;
&lt;br /&gt;
SSL is the abbreviation of Secured Socket Layer. It is a protocol enabling to settle a secured communication between two hosts. The origin host is viewed as an SSL client and the destination host as an SSL server.&lt;br /&gt;
&lt;br /&gt;
SSL has also been normalised as the TLS (Transport Layer Security) protocol. &lt;br /&gt;
&lt;br /&gt;
'''SSL is used on top of a transport level protocol''' like HTTP or FTP in order to secure it. &lt;br /&gt;
&lt;br /&gt;
SSL enables : &lt;br /&gt;
* authentication of the destination host for the origin host or mutual authentication of both the origin and the destination hosts&lt;br /&gt;
* data confidentiality through encryption&lt;br /&gt;
* data integrity checking through hashing.&lt;br /&gt;
&lt;br /&gt;
SSL relies on two types of encryption :&lt;br /&gt;
* public key encryption in the initiation phase, where authentication takes place&lt;br /&gt;
* secret key encryption when a session has been established and data is sent between two peers which trust each other.&lt;br /&gt;
&lt;br /&gt;
'''SSL only secures the communication between two endpoints''' : in the origin and destination points, data is in clear text, unless it is encrypted by another means, at the application level.&lt;br /&gt;
&lt;br /&gt;
==How SSL is implemented in J2EE==&lt;br /&gt;
&lt;br /&gt;
The following guide explains implementing SSL / 2 way SSL / Keystores etc&lt;br /&gt;
[http://sites.google.com/site/ssljavaguide/Home[http://sites.google.com/site/ssljavaguide/Home]]&lt;br /&gt;
&lt;br /&gt;
==HTTPS best practices in general==&lt;br /&gt;
&lt;br /&gt;
===Secure Login Pages===&lt;br /&gt;
There are several major considerations for securely designing a login page. The following text will address the considerations with regards to SSL.&lt;br /&gt;
&lt;br /&gt;
* '''Logins Most Post to an SSL Page'''&lt;br /&gt;
This is pretty obvious. The username and password must be posted over an SSL connection. If you look at the action element of the form it should be https.&lt;br /&gt;
* '''Login Landing Page Must Use SSL'''&lt;br /&gt;
The actual page where the user fills out the form must be an HTTPS page. If its not, an attacker could modify the page as it is sent to the user and change the form submission location or insert JavaScript which steals the username/password as it is typed.&lt;br /&gt;
* '''There must be no SSL Error or Warning Messages'''&lt;br /&gt;
The presence of any SSL warning message is a failure. Some of these error messages are legitimate security concerns; others desensitize the users against real security concerns since they blindly click accept. The presence of any SSL error message is unacceptable - even domain name mismatch for the www. &lt;br /&gt;
* '''HTTP connections should be dropped'''&lt;br /&gt;
If a user attempts to connect to the HTTP version of the login page the connection should be denied. One strategy is to automatically redirect HTTP connections to HTTPS connections. While this does get the user to the secure page there is one lingering risk. An attacker performing a man in the middle attack could intercept the HTTP redirect response and send the user to an alternate page.&lt;br /&gt;
&lt;br /&gt;
==HTTPS best practices in J2EE==&lt;br /&gt;
==Examples with Tomcat==&lt;br /&gt;
==Examples with JBoss==&lt;br /&gt;
&lt;br /&gt;
==Examples with Jetty==&lt;br /&gt;
&lt;br /&gt;
See [http://docs.codehaus.org/display/JETTY/How+to+configure+SSL How to configure SSL] for Jetty&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Canmanjoe</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SSL_Best_Practices&amp;diff=57140</id>
		<title>SSL Best Practices</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SSL_Best_Practices&amp;diff=57140"/>
				<updated>2009-03-22T10:20:46Z</updated>
		
		<summary type="html">&lt;p&gt;Canmanjoe: /* How SSL is implemented in J2EE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Status ==&lt;br /&gt;
Draft&lt;br /&gt;
&lt;br /&gt;
==What is SSL==&lt;br /&gt;
&lt;br /&gt;
SSL is the abbreviation of Secured Socket Layer. It is a protocol enabling to settle a secured communication between two hosts. The origin host is viewed as an SSL client and the destination host as an SSL server.&lt;br /&gt;
&lt;br /&gt;
SSL has also been normalised as the TLS (Transport Layer Security) protocol. &lt;br /&gt;
&lt;br /&gt;
'''SSL is used on top of a transport level protocol''' like HTTP or FTP in order to secure it. &lt;br /&gt;
&lt;br /&gt;
SSL enables : &lt;br /&gt;
* authentication of the destination host for the origin host or mutual authentication of both the origin and the destination hosts&lt;br /&gt;
* data confidentiality through encryption&lt;br /&gt;
* data integrity checking through hashing.&lt;br /&gt;
&lt;br /&gt;
SSL relies on two types of encryption :&lt;br /&gt;
* public key encryption in the initiation phase, where authentication takes place&lt;br /&gt;
* secret key encryption when a session has been established and data is sent between two peers which trust each other.&lt;br /&gt;
&lt;br /&gt;
'''SSL only secures the communication between two endpoints''' : in the origin and destination points, data is in clear text, unless it is encrypted by another means, at the application level.&lt;br /&gt;
&lt;br /&gt;
==How SSL is implemented in J2EE==&lt;br /&gt;
&lt;br /&gt;
The following guide explains implementing SSL / 2 way SSL / Keystores etc&lt;br /&gt;
[[http://sites.google.com/site/ssljavaguide/Home]]&lt;br /&gt;
&lt;br /&gt;
==HTTPS best practices in general==&lt;br /&gt;
&lt;br /&gt;
===Secure Login Pages===&lt;br /&gt;
There are several major considerations for securely designing a login page. The following text will address the considerations with regards to SSL.&lt;br /&gt;
&lt;br /&gt;
* '''Logins Most Post to an SSL Page'''&lt;br /&gt;
This is pretty obvious. The username and password must be posted over an SSL connection. If you look at the action element of the form it should be https.&lt;br /&gt;
* '''Login Landing Page Must Use SSL'''&lt;br /&gt;
The actual page where the user fills out the form must be an HTTPS page. If its not, an attacker could modify the page as it is sent to the user and change the form submission location or insert JavaScript which steals the username/password as it is typed.&lt;br /&gt;
* '''There must be no SSL Error or Warning Messages'''&lt;br /&gt;
The presence of any SSL warning message is a failure. Some of these error messages are legitimate security concerns; others desensitize the users against real security concerns since they blindly click accept. The presence of any SSL error message is unacceptable - even domain name mismatch for the www. &lt;br /&gt;
* '''HTTP connections should be dropped'''&lt;br /&gt;
If a user attempts to connect to the HTTP version of the login page the connection should be denied. One strategy is to automatically redirect HTTP connections to HTTPS connections. While this does get the user to the secure page there is one lingering risk. An attacker performing a man in the middle attack could intercept the HTTP redirect response and send the user to an alternate page.&lt;br /&gt;
&lt;br /&gt;
==HTTPS best practices in J2EE==&lt;br /&gt;
==Examples with Tomcat==&lt;br /&gt;
==Examples with JBoss==&lt;br /&gt;
&lt;br /&gt;
==Examples with Jetty==&lt;br /&gt;
&lt;br /&gt;
See [http://docs.codehaus.org/display/JETTY/How+to+configure+SSL How to configure SSL] for Jetty&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Canmanjoe</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Hashing_Java&amp;diff=19202</id>
		<title>Hashing Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Hashing_Java&amp;diff=19202"/>
				<updated>2007-06-18T14:13:21Z</updated>
		
		<summary type="html">&lt;p&gt;Canmanjoe: /* Why add salt ? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction :==&lt;br /&gt;
&lt;br /&gt;
Most of today’s applications use login/password in order to authenticate. Users often use the same login/password for different kinds of applications. If the couple is stolen, everybody can access all the applications the user has access to. &lt;br /&gt;
&lt;br /&gt;
Too often passwords are stored as clear text. Thus the password can be read directly by the database’s administrator, super users or SQL Injection attack etc. The backup media is also vulnerable. &lt;br /&gt;
In order to solve this problem, passwords must be stored encrypted. Two kinds of encryption are available:&lt;br /&gt;
* One way functions (SHA-256 SHA-1 MD5, ..;) also known as Hashing functions&lt;br /&gt;
* Reversible encryption functions (DES, AES, …). &lt;br /&gt;
However, the reversible property of encryption function is useless for credentials storing (cf. OWASP Guide v2.0.1) :&lt;br /&gt;
&lt;br /&gt;
''Passwords are secrets. There is no reason to decrypt them under any circumstances. Helpdesk staff should be able to set new passwords (with an audit trail, obviously), not read back old passwords. Therefore, there is no reason to store passwords in a reversible form.''&lt;br /&gt;
&lt;br /&gt;
==Definition of  cryptographic Hashing function:==&lt;br /&gt;
A Hash function creates a fixed length small fingerprint (or message digest) from an unlimited input string.&lt;br /&gt;
&lt;br /&gt;
hash(X) -&amp;gt;Y          X is a infinite set and Y is a finite set.&lt;br /&gt;
&lt;br /&gt;
A good cryptographic Hash function must have these properties: &lt;br /&gt;
* Preimage  resistant : From the function output y it must impossible to compute the input x such that hash(x)=y. &lt;br /&gt;
* Second preimage  resistant : from an input x1 it must impossible to compute another input x2 (different of x1) such that hash(x1)=hash(x2).&lt;br /&gt;
* Collision resistant : It must be difficult to find two inputs x1 and x2 (x1&amp;lt;&amp;gt;x2) such that hash(x1)=hash(x2).&lt;br /&gt;
&lt;br /&gt;
'''Sample java code :''' &lt;br /&gt;
  import java.security.MessageDigest;&lt;br /&gt;
  &lt;br /&gt;
  public byte[] getHash(String password) throws NoSuchAlgorithmException {&lt;br /&gt;
        MessageDigest digest = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
        digest.reset();&lt;br /&gt;
        byte[] input = digest.digest(password.getBytes());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Credential storage.==&lt;br /&gt;
&lt;br /&gt;
If the password’s digest is stored in a database, an attacker should be unable to recover the password thanks to the preimage resistance. The only way to go past this would be a [[Brute force attack|brute force attack]], i.e. computing the hash of all possible passwords or a dictionary attack, i.e. computing all the often used password.&lt;br /&gt;
&lt;br /&gt;
==Why add salt ? ==&lt;br /&gt;
&lt;br /&gt;
There are two drawbacks to choosing to only store the password’s hash: &lt;br /&gt;
*	It is possible to identify two identical passwords.&lt;br /&gt;
*	Due to the birthday paradox (http://en.wikipedia.org/wiki/Birthday_paradox), the attacker can find a password very quickly especially if the number of password is important in the database.&lt;br /&gt;
&lt;br /&gt;
In order to solve these problems, a salt can be concatenated to the password before the digest operation. &lt;br /&gt;
&lt;br /&gt;
A salt is a random number of a fixed length. This salt must be different for each stored entry. It must be stored as clear text next to the hashed password.&lt;br /&gt;
&lt;br /&gt;
In this configuration, an attacker must handle a brute force attack on each individual password. The database is now birthday attack resistant.&lt;br /&gt;
&lt;br /&gt;
A 64 bits salt is recommended in RSA PKCS5 standard.&lt;br /&gt;
&lt;br /&gt;
'''Sample java code :''' &lt;br /&gt;
  import java.security.MessageDigest;&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  public byte[] getHash(String password, byte[] salt) throws NoSuchAlgorithmException {&lt;br /&gt;
        MessageDigest digest = MessageDigest.getInstance(&amp;quot;SHA-256&amp;quot;);&lt;br /&gt;
        digest.reset();&lt;br /&gt;
        digest.update(salt);&lt;br /&gt;
        return digest.digest(password.getBytes());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Hardening against the attacker's attack==&lt;br /&gt;
&lt;br /&gt;
To slow down the computation it is recommended to iterate the hash operation n times. Because hashing is a fast operation, it slows down by a n factor an attacker but not a legitimate user. &lt;br /&gt;
A minimum of 1000 operations is recommended in RSA PKCS5 standard.&lt;br /&gt;
&lt;br /&gt;
The stored password looks like this :&lt;br /&gt;
		Hash(hash(hash(hash(……….hash(password||salt)))))))))))))))&lt;br /&gt;
&lt;br /&gt;
To authenticate a user, the operation same as above must be performed, followed by a comparison of the two hashes.&lt;br /&gt;
&lt;br /&gt;
The hash function you need to use depends of your security policy. SHA-256 or SHA-512 is recommended for long term storage.&lt;br /&gt;
&lt;br /&gt;
'''Sample java code :''' &lt;br /&gt;
  import java.security.*;&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
   public byte[] getHash(int iterationNb, String password, byte[] salt) throws NoSuchAlgorithmException {&lt;br /&gt;
        MessageDigest digest = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
        digest.reset();&lt;br /&gt;
        digest.update(salt);&lt;br /&gt;
        byte[] input = digest.digest(password.getBytes());&lt;br /&gt;
        for (int i = 0; i &amp;lt; iterationNb; i++) {&lt;br /&gt;
            digest.reset();&lt;br /&gt;
            input = digest.digest(input);&lt;br /&gt;
        }&lt;br /&gt;
        return input;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Complete Java Sample==&lt;br /&gt;
In order to create the table needed by this application, call the method creerTable().&lt;br /&gt;
It creates a TABLE called CREDENTIAL, with these fields : &lt;br /&gt;
* LOGIN VARCHAR (100)  PRIMARY KEY&lt;br /&gt;
* PASSWORD VARCHAR (32)&lt;br /&gt;
* SALT VARCHAR (32)&lt;br /&gt;
&lt;br /&gt;
In this database, the password and the salt are stored in Base64 representation.&lt;br /&gt;
&lt;br /&gt;
The method ''authenticate'' is used in order to authenticate a user, the method ''createUser'' is used to create a new user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  package org.psafix.memopwd;&lt;br /&gt;
  &lt;br /&gt;
  import java.security.MessageDigest;&lt;br /&gt;
  import java.security.NoSuchAlgorithmException;&lt;br /&gt;
  import java.io.IOException;&lt;br /&gt;
  import sun.misc.BASE64Decoder;&lt;br /&gt;
  import sun.misc.BASE64Encoder;&lt;br /&gt;
  import java.sql.*;&lt;br /&gt;
  import java.util.Arrays;&lt;br /&gt;
  import java.security.SecureRandom;&lt;br /&gt;
  &lt;br /&gt;
  public class Owasp {&lt;br /&gt;
    private final static int ITERATION_NUMBER = 1000;&lt;br /&gt;
  &lt;br /&gt;
    public Owasp() {&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
    /**&lt;br /&gt;
     * Authenticates the user with a given login and password&lt;br /&gt;
     * If password and/or login is null then always returns false.&lt;br /&gt;
     * If the user does not exist in the database returns false.&lt;br /&gt;
     * @param con Connection An open connection to a databse&lt;br /&gt;
     * @param login String The login of the user&lt;br /&gt;
     * @param password String The password of the user&lt;br /&gt;
     * @return boolean Returns true if the user is authenticated, false otherwise&lt;br /&gt;
     * @throws SQLException If the database is inconsistent or unavailable (&lt;br /&gt;
     *           (Two users with the same login, salt or digested password altered etc.)&lt;br /&gt;
     * @throws NoSuchAlgorithmException If the algorithm SHA-1 is not supported by the JVM&lt;br /&gt;
     */&lt;br /&gt;
    public boolean authenticate(Connection con, String login, String password)&lt;br /&gt;
            throws SQLException, NoSuchAlgorithmException{&lt;br /&gt;
        boolean authenticated=false;&lt;br /&gt;
        PreparedStatement ps = null;&lt;br /&gt;
        ResultSet rs = null;&lt;br /&gt;
        try {&lt;br /&gt;
            boolean userExist = true;&lt;br /&gt;
            // INPUT VALIDATION&lt;br /&gt;
            if (login==null||password==null){&lt;br /&gt;
                // TIME RESISTANT ATTACK&lt;br /&gt;
                // Computation time is equal to the time needed by a legitimate user&lt;br /&gt;
                userExist = false;&lt;br /&gt;
                login=&amp;quot;&amp;quot;;&lt;br /&gt;
                password=&amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
  &lt;br /&gt;
            ps = con.prepareStatement(&amp;quot;SELECT PASSWORD, SALT FROM CREDENTIAL WHERE LOGIN = ?&amp;quot;);&lt;br /&gt;
            ps.setString(1, login);&lt;br /&gt;
            rs = ps.executeQuery();&lt;br /&gt;
            String digest, salt;&lt;br /&gt;
            if (rs.next()) {&lt;br /&gt;
                digest = rs.getString(&amp;quot;PASSWORD&amp;quot;);&lt;br /&gt;
                salt = rs.getString(&amp;quot;SALT&amp;quot;);&lt;br /&gt;
                // DATABASE VALIDATION&lt;br /&gt;
                if (digest == null || salt == null) {&lt;br /&gt;
                    throw new SQLException(&amp;quot;Database inconsistant Salt or Digested Password altered&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
                if (rs.next()) { // Should not append, because login is the primary key&lt;br /&gt;
                    throw new SQLException(&amp;quot;Database inconsistent two CREDENTIALS with the same LOGIN&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            } else { // TIME RESISTANT ATTACK (Even if the user does not exist the&lt;br /&gt;
                // Computation time is equal to the time needed for a legitimate user&lt;br /&gt;
                digest = &amp;quot;000000000000000000000000000=&amp;quot;;&lt;br /&gt;
                salt = &amp;quot;00000000000=&amp;quot;;&lt;br /&gt;
                userExist = false;&lt;br /&gt;
            }&lt;br /&gt;
  &lt;br /&gt;
            byte[] bDigest = base64ToByte(digest);&lt;br /&gt;
            byte[] bSalt = base64ToByte(salt);&lt;br /&gt;
  &lt;br /&gt;
            // Compute the new DIGEST&lt;br /&gt;
            byte[] proposedDigest = getHash(ITERATION_NUMBER, password, bSalt);&lt;br /&gt;
  &lt;br /&gt;
            return Arrays.equals(proposedDigest, bDigest) &amp;amp;&amp;amp; userExist;&lt;br /&gt;
        } catch (IOException ex){&lt;br /&gt;
            throw new SQLException(&amp;quot;Database inconsistant Salt or Digested Password altered&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        finally{&lt;br /&gt;
            close(rs);&lt;br /&gt;
            close(ps);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
    /**&lt;br /&gt;
     * Inserts a new user in the database&lt;br /&gt;
     * @param con Connection An open connection to a databse&lt;br /&gt;
     * @param login String The login of the user&lt;br /&gt;
     * @param password String The password of the user&lt;br /&gt;
     * @return boolean Returns true if the login and password are ok (not null and length(login)&amp;lt;=100&lt;br /&gt;
     * @throws SQLException If the database is unavailable&lt;br /&gt;
     * @throws NoSuchAlgorithmException If the algorithm SHA-1 or the SecureRandom is not supported by the JVM&lt;br /&gt;
     */&lt;br /&gt;
    public boolean createUser(Connection con, String login, String password)&lt;br /&gt;
            throws SQLException, NoSuchAlgorithmException&lt;br /&gt;
    {&lt;br /&gt;
        PreparedStatement ps = null;&lt;br /&gt;
        try {&lt;br /&gt;
            if (login!=null&amp;amp;&amp;amp;password!=null&amp;amp;&amp;amp;login.length()&amp;lt;=100){&lt;br /&gt;
                // Uses a secure Random not a simple Random&lt;br /&gt;
                SecureRandom random = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
                // Salt generation 64 bits long&lt;br /&gt;
                byte[] bSalt = new byte[8];&lt;br /&gt;
                random.nextBytes(bSalt);&lt;br /&gt;
                // Digest computation&lt;br /&gt;
                byte[] bDigest = getHash(ITERATION_NUMBER,password,bSalt);&lt;br /&gt;
                String sDigest = byteToBase64(bDigest);&lt;br /&gt;
                String sSalt = byteToBase64(bSalt);&lt;br /&gt;
  &lt;br /&gt;
                ps = con.prepareStatement(&amp;quot;INSERT INTO CREDENTIAL (LOGIN, PASSWORD, SALT) VALUES (?,?,?)&amp;quot;);&lt;br /&gt;
                ps.setString(1,login);&lt;br /&gt;
                ps.setString(2,sDigest);&lt;br /&gt;
                ps.setString(3,sSalt);&lt;br /&gt;
                ps.executeUpdate();&lt;br /&gt;
                return true;&lt;br /&gt;
            } else {&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        } finally {&lt;br /&gt;
            close(ps);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
    /**&lt;br /&gt;
     * From a password, a number of iterations and a salt,&lt;br /&gt;
     * returns the corresponding digest&lt;br /&gt;
     * @param iterationNb int The number of iterations of the algorithm&lt;br /&gt;
     * @param password String The password to encrypt&lt;br /&gt;
     * @param salt byte[] The salt&lt;br /&gt;
     * @return byte[] The digested password&lt;br /&gt;
     * @throws NoSuchAlgorithmException If the algorithm doesn't exist&lt;br /&gt;
     */&lt;br /&gt;
    public byte[] getHash(int iterationNb, String password, byte[] salt) throws NoSuchAlgorithmException {&lt;br /&gt;
        MessageDigest digest = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
        digest.reset();&lt;br /&gt;
        digest.update(salt);&lt;br /&gt;
        byte[] input = digest.digest(password.getBytes());&lt;br /&gt;
        for (int i = 0; i &amp;lt; iterationNb; i++) {&lt;br /&gt;
            digest.reset();&lt;br /&gt;
            input = digest.digest(input);&lt;br /&gt;
        }&lt;br /&gt;
        return input;&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
    public void creerTable(Connection con) throws SQLException{&lt;br /&gt;
        Statement st = null;&lt;br /&gt;
        try {&lt;br /&gt;
            st = con.createStatement();&lt;br /&gt;
            st.execute(&amp;quot;CREATE TABLE CREDENTIAL (LOGIN VARCHAR(100) PRIMARY KEY, PASSWORD VARCHAR(32) NOT NULL, SALT VARCHAR(32) NOT NULL)&amp;quot;);&lt;br /&gt;
        } finally {&lt;br /&gt;
            close(st);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
    /**&lt;br /&gt;
     * Closes the current statement&lt;br /&gt;
     * @param ps Statement&lt;br /&gt;
     */&lt;br /&gt;
    public void close(Statement ps) {&lt;br /&gt;
        if (ps!=null){&lt;br /&gt;
            try {&lt;br /&gt;
                ps.close();&lt;br /&gt;
            } catch (SQLException ignore) {&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
    /**&lt;br /&gt;
     * Closes the current resultset&lt;br /&gt;
     * @param ps Statement&lt;br /&gt;
     */&lt;br /&gt;
    public void close(ResultSet rs) {&lt;br /&gt;
        if (rs!=null){&lt;br /&gt;
            try {&lt;br /&gt;
                rs.close();&lt;br /&gt;
            } catch (SQLException ignore) {&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
    /**&lt;br /&gt;
     * From a base 64 representation, returns the corresponding byte[] &lt;br /&gt;
     * @param data String The base64 representation&lt;br /&gt;
     * @return byte[]&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     */&lt;br /&gt;
    public static byte[] base64ToByte(String data) throws IOException {&lt;br /&gt;
        BASE64Decoder decoder = new BASE64Decoder();&lt;br /&gt;
        return decoder.decodeBuffer(data);&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
    /**&lt;br /&gt;
     * From a byte[] returns a base 64 representation&lt;br /&gt;
     * @param data byte[]&lt;br /&gt;
     * @return String&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     */&lt;br /&gt;
    public static String byteToBase64(byte[] data){&lt;br /&gt;
        BASE64Encoder endecoder = new BASE64Encoder();&lt;br /&gt;
        return endecoder.encode(data);&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Canmanjoe</name></author>	</entry>

	</feed>