1 64 65 package com.jcorporate.expresso.core.security; 66 67 import com.jcorporate.expresso.kernel.exception.ChainedException; 68 import org.apache.log4j.Logger; 69 70 import java.security.MessageDigest ; 71 import java.security.NoSuchAlgorithmException ; 72 73 74 80 public final class StringHash { 81 private static final String thisClass = "com.jcorporate.expresso.core.security.strongencryption.StringHash"; 82 private MessageDigest sha; 83 static Logger logCat = Logger.getLogger(StringHash.class); 84 private CryptoManager cryptoManager; 85 86 89 public StringHash() 90 throws ChainedException { 91 try { 92 sha = MessageDigest.getInstance("SHA"); 93 logCat.debug("StringHash initialized and SHA-1 algorithm loaded"); 94 } catch (NoSuchAlgorithmException ex) { 95 logCat.error("Unable to load SHA-1 Hash Algorithm", ex); 96 throw new ChainedException(thisClass + ".StringHash()" + 97 ":Error loading SHA-1 Algorithm." + 98 " You may not have installed the" + 99 " Cryptography Extensions Properly:", 100 ex); 101 } 102 } 103 104 110 public byte[] produceHash(byte[] inputData) 111 throws ChainedException { 112 final String myName = thisClass + ".produceHash(byte)"; 113 114 if (inputData.length == 0) { 115 throw new IllegalArgumentException (myName + 116 " inputData's length must not be zero"); 117 } 118 if (logCat.isDebugEnabled()) { 119 logCat.debug("Producing a hash for the data: " + 120 new String (inputData)); 121 } 122 123 return sha.digest(inputData); 124 } 125 126 public void setCryptoManager(CryptoManager cryptoManager) { 127 this.cryptoManager = cryptoManager; 128 } 129 130 public CryptoManager getCryptoManager() { 131 return cryptoManager; 132 } 133 134 135 } 136 137 | Popular Tags |