1 19 20 package net.sourceforge.jcetaglib.taglib.crypto; 21 22 import net.sourceforge.jcetaglib.lib.Clean; 23 import net.sourceforge.jcetaglib.lib.Keystore; 24 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 49 public class GenerateKey extends TagSupport { 50 private String algorithm = "AES"; private int strength = 256; private String seed; private String keyfile; private StringBuffer passphrase; 56 public int doStartTag() throws JspException { 57 58 try { 59 if (seed == null) { 60 Keystore.generateKey(algorithm, strength, null, keyfile, passphrase); 61 } else { 62 Keystore.generateKey(algorithm, strength, seed.getBytes(), keyfile, passphrase); 63 } 64 } catch (Exception e) { 65 e.printStackTrace(); 66 throw new JspException ("JCE Exception: " + e.getMessage(), e); 67 } finally { 68 this.release(); 69 } 70 71 return SKIP_BODY; 72 } 73 74 public void release() { 75 Clean.blank(passphrase); 77 78 super.release(); 79 } 81 88 public void setAlgorithm(String algorithm) { 89 this.algorithm = algorithm; 90 } 91 92 99 public void setStrength(int strength) { 100 this.strength = strength; 101 } 102 103 110 public void setSeed(String seed) { 111 this.seed = seed; 112 } 113 114 121 public void setKeyfile(String keyfile) { 122 this.keyfile = keyfile; 123 } 124 125 132 public void setPassphrase(StringBuffer passphrase) { 133 this.passphrase = passphrase; 134 } 135 } | Popular Tags |