Example usage for org.apache.shiro.crypto.hash Md5Hash Md5Hash

List of usage examples for org.apache.shiro.crypto.hash Md5Hash Md5Hash

Introduction

In this page you can find the example usage for org.apache.shiro.crypto.hash Md5Hash Md5Hash.

Prototype

public Md5Hash(Object source, Object salt, int hashIterations) 

Source Link

Usage

From source file:com.echounion.portal.util.kit.ShiroKit.java

License:Apache License

/**
 * .//from ww  w. j av  a  2s . com
 * @param password ?
 * @param salt  ?
 * @return  ?
 */
public static String md5(final String password, final String salt) {
    String p;
    p = new Md5Hash(password, salt, 2).toHex();
    return p;
}

From source file:com.once.crosscloud.utils.EndecryptUtils.java

License:Apache License

/** 
 * ?md5,salt?User //from w  ww.j  a v  a 2  s  .c  om
 * @param username ?? 
 * @param password ?
 * @param hashIterations  
 * @return UserEntity?salt 
 */
public static UserEntity md5Password(String username, String password, int hashIterations) {
    SecureRandomNumberGenerator secureRandomNumberGenerator = new SecureRandomNumberGenerator();
    String salt = secureRandomNumberGenerator.nextBytes().toHex();
    //?username,? 
    String password_cryto = new Md5Hash(password, username + salt, hashIterations).toBase64();
    UserEntity user = new UserEntity();
    user.setPassword(password_cryto);
    user.setCredentialsSalt(salt);
    user.setUserName(username);
    return user;
}

From source file:com.once.crosscloud.utils.EndecryptUtils.java

License:Apache License

public static void main(String[] args) {
    String password = "admin";
    String cipherText = encrytHex(password);
    System.out.println(password + "hex?" + cipherText);
    String decrptPassword = decryptHex(cipherText);
    System.out.println(cipherText + "hex??" + decrptPassword);
    String cipherText_base64 = encrytBase64(password);
    System.out.println(password + "base64?" + cipherText_base64);
    String decrptPassword_base64 = decryptBase64(cipherText_base64);
    System.out.println(cipherText_base64 + "base64??" + decrptPassword_base64);
    String h64 = H64.encodeToString(password.getBytes());
    System.out.println(h64);//from   w w  w  .  jav  a2 s .c om
    String salt = "7road";
    String cipherText_md5 = new Md5Hash(password, salt, 4).toHex();
    System.out.println(password + "md5?" + cipherText_md5);
    System.out.println(generateKey());
    System.out.println("==========================================================");
    AesCipherService aesCipherService = new AesCipherService();
    aesCipherService.setKeySize(128);
    Key key = aesCipherService.generateNewKey();
    String aes_cipherText = aesCipherService.encrypt(password.getBytes(), key.getEncoded()).toHex();
    System.out.println(password + " aes" + aes_cipherText);
    String aes_mingwen = new String(
            aesCipherService.decrypt(Hex.decode(aes_cipherText), key.getEncoded()).getBytes());
    System.out.println(aes_cipherText + " aes" + aes_mingwen);
}

From source file:com.zht.common.shiro.util.EndecryptUtils.java

License:Apache License

/**
 * userName :{admin}/*from w w  w .j av  a2 s .c o  m*/
  page_password :{123456}
  page_salt :{admin@zhtframework_94DABGioQOq2tTUO0AXYow}
  //83da8e102358e921cc1ee088138b74d4
  password_from_page :{3335672fa546d2d2c8fa5a102027b00d}
          
  genRandomSalt :{3293523627878424jm4eSkDtFd4KSM8yWSMqp}
  encptyedPasswod :{fe6f642c4e184a504e142be37eaa4a59}
 * @param argd
 */
public static void main(String[] argd) {//eef3a22a128d5adb5699e3c7da7a6fc8
    String page_salt = GlobleConstant.pageSalt;
    String userName = "admin";
    String page_password = "123456";
    String password_from_page = new Md5Hash(page_password, userName + page_salt, 1).toString();

    System.out.println("userName :{" + userName + "}");
    System.out.println("page_salt :{" + userName + page_salt + "}");
    System.out.println("page_password :{" + page_password + "}");

    System.out.println("password_from_page :{" + password_from_page + "}");

    String genSalt = genRandomSalt();
    String encptyPass = genPassword(password_from_page, genSalt, 2);

    System.out.println("genRandomSalt :{" + genSalt + "}");

    System.out.println("encptyedPasswod :{" + encptyPass + "}");
}

From source file:com.zht.common.shiro.util.EndecryptUtils.java

License:Apache License

public static String[] genDefaultUserPassSalt(String userName, String password) {
    String page_salt = GlobleConstant.pageSalt;
    String password_from_page = new Md5Hash(password, userName + page_salt, 1).toString();
    String genSalt = genRandomSalt();
    String encptyPass = genPassword(password_from_page, genSalt, 2);
    String[] res = new String[] { encptyPass, genSalt };
    return res;//from w w w  .  java  2 s .  co  m
}

From source file:com.zht.common.shiro.util.EndecryptUtils.java

License:Apache License

/**
 * ?Md5Hash salt?  ? ? dist(salt+password),? password+{salt}?
 * ?MD5? //from   w ww . j a v  a  2  s.co m
 * @param password
 * @param salt
 * @return
 */
public static String genPassword(String password, String salt, int times) {
    String password_cipherText2 = new Md5Hash(password, salt, times).toHex().toString();
    return password_cipherText2;
}

From source file:org.qi4j.library.shiro.crypto.HashFactory.java

License:Open Source License

public static Hash create(String algorithmName, Object source, Object salt, int hashIterations) {
    if (algorithmName == null || algorithmName.length() <= 0) {
        throw new IllegalArgumentException("Algorithm name was null or empty");
    }//  w  ww.j  a  v a2  s. c om
    if (!Arrays.asList(VALID_ALGORITHM_NAMES).contains(algorithmName)) {
        throw new IllegalArgumentException(algorithmName + " is not a valid algorithm. Valid ones are : "
                + Arrays.toString(VALID_ALGORITHM_NAMES));
    }
    if (Md2Hash.ALGORITHM_NAME.equals(algorithmName)) {
        return new Md2Hash(source, salt, hashIterations);
    }
    if (Md5Hash.ALGORITHM_NAME.equals(algorithmName)) {
        return new Md5Hash(source, salt, hashIterations);
    }
    if (Sha1Hash.ALGORITHM_NAME.equals(algorithmName)) {
        return new Sha1Hash(source, salt, hashIterations);
    }
    if (Sha256Hash.ALGORITHM_NAME.equals(algorithmName)) {
        return new Sha256Hash(source, salt, hashIterations);
    }
    if (Sha384Hash.ALGORITHM_NAME.equals(algorithmName)) {
        return new Sha384Hash(source, salt, hashIterations);
    }
    if (Sha512Hash.ALGORITHM_NAME.equals(algorithmName)) {
        return new Sha512Hash(source, salt, hashIterations);
    }
    throw new InternalError("You shall not pass!");
}

From source file:org.zht.framework.util.MD5Util.java

License:Apache License

/**
 * @param args/*from   ww w  . j  a v  a 2s . c o m*/
 * 46564af66321701225b7f04e19bfcc08
 * 46564af66321701225b7f04e19bfcc08
 */
public static void main(String[] args) {
    String pass = "123456";
    String salt = "shiro";//a05bd3699caee8947540997aedb064f6
    String result = null;
    //      result = encodeWithSalt(pass, salt);
    result = encodeWithSalt(pass, salt);
    System.out.println(result);
    System.out.println("----------------------------");
    String password_cipherText = new Md5Hash(pass, salt, 1).toHex();
    System.out.println(password_cipherText);//eef3a22a128d5adb5699e3c7da7a6fc8
}