1 28 package net.sf.jguard.ext.authentication; 29 30 import java.security.NoSuchAlgorithmException ; 31 import java.security.Provider ; 32 import java.security.Security ; 33 import java.util.Arrays ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 37 import net.sf.jguard.ext.util.CryptUtils; 38 39 import junit.framework.TestCase; 40 41 public class CryptUtilsTest extends TestCase { 42 43 46 public void testCryptPassword() { 47 48 displayProvidersInformations(); 49 50 String password1 = "success"; 51 String md5FromPassword1ShouldBe="260ca9dd8a4577fc00b7bd5810298076"; 52 try { 54 55 new String (CryptUtils.cryptPassword(password1.toCharArray())); 57 assertEquals(password1,password1); 58 59 CryptUtils.setDigestAlgorithm("MD5"); 61 String result1 = new String (CryptUtils.cryptPassword(password1.toCharArray())); 62 assertEquals(md5FromPassword1ShouldBe,result1); 63 64 65 66 } catch (NoSuchAlgorithmException e) { 67 System.out.println(e.getMessage()); 68 fail(); 69 } 70 71 } 72 73 private void displayProvidersInformations() { 74 List providers= Arrays.asList(Security.getProviders()); 75 Iterator it = providers.iterator(); 76 while(it.hasNext()){ 77 Provider prov = (Provider )it.next(); 78 System.out.println(prov.getInfo()); 79 } 80 } 81 82 83 } 84 | Popular Tags |