1 23 package org.openharmonise.rm.security.authentication; 24 25 import org.apache.commons.math.random.*; 26 27 28 32 public class PasswordCryptUtil { 33 34 private static RandomData random; 35 36 40 public static String getNewSalt(int i) { 41 if (random == null) { 42 random = new RandomDataImpl(); 43 } 44 return random.nextSecureHexString(i); 45 } 46 47 public static void main(String [] args) { 48 try { 50 String superSalt = PasswordCryptUtil.getNewSalt(32); 51 System.out.println("MD 5 - super salt: " + superSalt); 52 PasswordHelper passwordHelper = new CryptPasswordHelper("MD5"); 53 String superPassword = passwordHelper.getNewPassword("Tanger1ne", superSalt); 54 System.out.println("MD 5 - super hashed password: " + superPassword); 55 56 superSalt = PasswordCryptUtil.getNewSalt(40); 57 System.out.println("SHA-1 - super salt: " + superSalt); 58 passwordHelper = new CryptPasswordHelper("SHA-1"); 59 superPassword = passwordHelper.getNewPassword("Tanger1ne", superSalt); 60 System.out.println("SHA-1 - super hashed password: " + superPassword); 61 } 62 catch (RuntimeException e) { 63 e.printStackTrace(); 65 } 66 } 67 68 } 69 | Popular Tags |