All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yestech.lib.crypto.ApacheConversionFactory Maven / Gradle / Ivy

Go to download

A collection of classes that can be used across yestech artifacts/components, but must not be dependant on any yestech component. Most of the code is utility type code. When more than a few classes are found to be in a package or the package start to handle more that a few reposibilities then a new independant component is created and the existing code in yeslib is ported to the new component.

There is a newer version: 1.2.0
Show newest version
/*
 * Copyright LGPL3
 * YES Technology Association
 * http://yestech.org
 *
 * http://www.opensource.org/licenses/lgpl-3.0.html
 */

/*
 *
 * Author:  Artie Copeland
 * Last Modified Date: $DateTime: $
 */
package org.yestech.lib.crypto;

import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Date;

/**
 * @author Artie Copeland
 * @version $Revision: $
 */
public class ApacheConversionFactory implements IPasswordConversionFactory {

    /**
     * Encodes a password that adheres to Apache.
     *
     * @param password
     * @return The password
     */
    @Override
    public String transform(String password, Object... params) {
        String convertedPassword = null;
        if (params == null || params.length < 1) {
            convertedPassword = toApacheMD5Crypt(password);
        } else {
            convertedPassword = toApacheMD5Crypt(params[0].toString(), password);
        }
        return convertedPassword;
    }


    /**
     * Convert a String to a Apache Crypt Representation. The original
     * is the clear text password.
     *
     * @param original Unencrypted value
     * @return The encrypted value
     */
    private String toApacheMD5Crypt(String original) {

        return MD5Crypt.apacheCrypt(original);
    }

    /**
     * Convert a String to a Apache MD5 Crypt Representation.  Usually salt is a random string
     * and original is the clear text password.
     *
     * @param salt     Salt to use for encryption
     * @param original Unencrypted value
     * @return The encrypted value
     */
    private String toApacheMD5Crypt(String salt, String original) {
        return MD5Crypt.apacheCrypt(salt, original);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy