1 19 20 package com.sslexplorer.jdbc.hsqldb; 21 22 import java.io.UnsupportedEncodingException ; 23 import java.security.MessageDigest ; 24 import java.security.NoSuchAlgorithmException ; 25 import java.util.regex.Matcher ; 26 import java.util.regex.Pattern ; 27 28 import com.maverick.crypto.encoders.Base64; 29 import com.sslexplorer.boot.ReplacementEngine; 30 31 37 public class DBFunctions { 38 39 47 public static String matches(String text, String regex) { 48 Pattern pattern = ReplacementEngine.getPatternPool().getPattern(regex, false, false); 49 try { 50 Matcher matcher = pattern.matcher(text); 51 return matcher.find() ? text : ""; 52 } finally { 53 ReplacementEngine.getPatternPool().releasePattern(pattern); 54 } 55 } 56 57 61 public static String password(String text) throws UnsupportedEncodingException , NoSuchAlgorithmException { 62 return digest(text); 63 } 64 65 74 public static String encPassword(String password) throws UnsupportedEncodingException , NoSuchAlgorithmException { 75 String encoded = encode(digest(password)); 76 return encoded; 77 } 78 79 85 public static String encode(String string) { 86 return new String (Base64.encode(string.getBytes())); 87 } 88 89 95 public static String decode(String string) { 96 return new String (Base64.decode(string.getBytes())); 97 } 98 99 105 public static String digest(String string) throws NoSuchAlgorithmException , UnsupportedEncodingException { 106 byte[] b = string.getBytes(); 107 MessageDigest md = MessageDigest.getInstance("MD5"); 108 md.update(b); 109 byte[] digest = md.digest(); 110 return new String (digest); 111 } 112 113 } 114 | Popular Tags |